diff --git a/README.md b/README.md index f05ac9e12..ca7203cf3 100644 --- a/README.md +++ b/README.md @@ -42,15 +42,19 @@ This is the development monorepo for StyleX. - `examples` - Contains examples using StyleX and its integration with build tools. - `packages` - - Contains the individual packages managed in the monorepo. + - Contains the public and private packages managed in the monorepo. - [babel-plugin](https://github.com/facebook/stylex/blob/main/packages/babel-plugin) + - [benchmarks](https://github.com/facebook/stylex/blob/main/packages/benchmarks) - [cli](https://github.com/facebook/stylex/blob/main/packages/cli) + - [docs](https://github.com/facebook/stylex/blob/main/packages/docs) - [eslint-plugin](https://github.com/facebook/stylex/blob/main/packages/eslint-plugin) - - [open-props](https://github.com/facebook/stylex/blob/main/packages/open-props) + - [postcss-plugin](https://github.com/facebook/stylex/blob/main/packages/postcss-plugin) - [rollup-plugin](https://github.com/facebook/stylex/blob/main/packages/rollup-plugin) + - [scripts](https://github.com/facebook/stylex/blob/main/packages/scripts) - [shared](https://github.com/facebook/stylex/blob/main/packages/shared) + - [style-value-parser](https://github.com/facebook/stylex/blob/main/packages/style-value-parser) - [stylex](https://github.com/facebook/stylex/blob/main/packages/stylex) - - [webpack-plugin](https://github.com/facebook/stylex/blob/main/packages/webpack-plugin) + ### Tasks diff --git a/package-lock.json b/package-lock.json index 69ccece5a..76d5166d2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3696,6 +3696,7 @@ "cpu": [ "ppc64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3712,6 +3713,7 @@ "cpu": [ "arm" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3728,6 +3730,7 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3744,6 +3747,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3760,6 +3764,7 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3776,6 +3781,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3792,6 +3798,7 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3808,6 +3815,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3824,6 +3832,7 @@ "cpu": [ "arm" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3840,6 +3849,7 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3856,6 +3866,7 @@ "cpu": [ "ia32" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3872,6 +3883,7 @@ "cpu": [ "loong64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3888,6 +3900,7 @@ "cpu": [ "mips64el" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3904,6 +3917,7 @@ "cpu": [ "ppc64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3920,6 +3934,7 @@ "cpu": [ "riscv64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3936,6 +3951,7 @@ "cpu": [ "s390x" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3952,6 +3968,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3968,6 +3985,7 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -3984,6 +4002,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -4000,6 +4019,7 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -4016,6 +4036,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -4032,6 +4053,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -4048,6 +4070,7 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -4064,6 +4087,7 @@ "cpu": [ "ia32" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -4080,6 +4104,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -8583,6 +8608,7 @@ "version": "0.26.0", "resolved": "https://registry.npmjs.org/babel-plugin-syntax-hermes-parser/-/babel-plugin-syntax-hermes-parser-0.26.0.tgz", "integrity": "sha512-gU/U5ASnPmm1GY9vptiJF20BNsULFuetjJX6gvNdJCUsftbFQ1STGYMOfkFgVTtpZo+iGTz4tzDNA/IW0U8dvA==", + "dev": true, "license": "MIT", "dependencies": { "hermes-parser": "0.26.0" @@ -11344,6 +11370,7 @@ "version": "0.25.1", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.1.tgz", "integrity": "sha512-BGO5LtrGC7vxnqucAe/rmvKdJllfGaYWdyABvyMoXQlfYMb2bbRuReWR5tEGE//4LcNJj9XrkovTqNYRFZHAMQ==", + "dev": true, "hasInstallScript": true, "license": "MIT", "bin": { @@ -25936,6 +25963,7 @@ "packages/esbuild-plugin": { "name": "@stylexjs/esbuild-plugin", "version": "0.11.1", + "dev": true, "license": "MIT", "dependencies": { "@babel/core": "^7.26.8", @@ -26099,6 +26127,7 @@ "packages/webpack-plugin": { "name": "@stylexjs/webpack-plugin", "version": "0.11.1", + "dev": true, "license": "MIT", "dependencies": { "@babel/core": "^7.26.8", diff --git a/packages/docs/docs/learn/03-installation.mdx b/packages/docs/docs/learn/03-installation.mdx index 189f58c16..b989d1535 100755 --- a/packages/docs/docs/learn/03-installation.mdx +++ b/packages/docs/docs/learn/03-installation.mdx @@ -129,103 +129,6 @@ and esbuild. ``` -
- Webpack - - - - ```tsx title="webpack.config.js" - const StylexPlugin = require('@stylexjs/webpack-plugin'); - const path = require('path'); - - const config = (env, argv) => ({ - entry: { - main: './src/index.js', - }, - output: { - path: path.resolve(__dirname, '.build'), - filename: '[name].js', - }, - module: { - rules: [ - { - test: /\.js$/, - exclude: /node_modules/, - use: 'babel-loader', - }, - ], - }, - plugins: [ - // Ensure that the stylex plugin is used before Babel - new StylexPlugin({ - filename: 'styles.[contenthash].css', - // get webpack mode and set value for dev - dev: argv.mode === 'development', - // Use statically generated CSS files and not runtime injected CSS. - // Even in development. - runtimeInjection: false, - // optional. default: 'x' - classNamePrefix: 'x', - // Required for CSS variable support - unstable_moduleResolution: { - // type: 'commonJS' | 'haste' - // default: 'commonJS' - type: 'commonJS', - // The absolute path to the root directory of your project - rootDir: __dirname, - }, - }), - ], - cache: true, - }); - - module.exports = config; - ``` - -
- -
- esbuild - - - - ```tsx title="build.mjs" - import esbuild from 'esbuild'; - import stylexPlugin from '@stylexjs/esbuild-plugin'; - import path from 'path'; - import { fileURLToPath } from 'url'; - - const __dirname = path.dirname(fileURLToPath(import.meta.url)); - - esbuild.build({ - entryPoints: ['src/index.js'], - bundle: true, - outfile: './build/bundle.js', - minify: true, - plugins: [ - stylexPlugin({ - // If set to 'true', bundler will inject styles in-line - // Do not use in production - dev: false, - // Required. File path for the generated CSS file - generatedCSSFileName: path.resolve(__dirname, 'build/stylex.css'), - // Aliases for StyleX package imports - // default: '@stylexjs/stylex' - stylexImports: ['@stylexjs/stylex'], - // Required for CSS variable support - unstable_moduleResolution: { - // type: 'commonJS' | 'haste' - // default: 'commonJS' - type: 'commonJS', - // The absolute path to the root of your project - rootDir: __dirname, - }, - }), - ], - }) - ``` -
- Please refer to the [StyleX examples](https://github.com/facebook/stylex/tree/main/examples) for demonstrations on how to use each of these plugins. diff --git a/packages/esbuild-plugin/.babelrc.cjs b/packages/esbuild-plugin/.babelrc.cjs deleted file mode 100644 index ccbdb3201..000000000 --- a/packages/esbuild-plugin/.babelrc.cjs +++ /dev/null @@ -1,17 +0,0 @@ -module.exports = { - assumptions: { - iterableIsArray: true, - }, - presets: [ - [ - '@babel/preset-env', - { - exclude: ['@babel/plugin-transform-typeof-symbol'], - targets: 'defaults', - modules: process.env.NODE_ENV === 'test' ? 'commonjs' : false, - }, - ], - '@babel/preset-flow', - ], - plugins: [['babel-plugin-syntax-hermes-parser', { flow: 'detect' }]], -}; diff --git a/packages/esbuild-plugin/README.md b/packages/esbuild-plugin/README.md deleted file mode 100644 index a4318ed69..000000000 --- a/packages/esbuild-plugin/README.md +++ /dev/null @@ -1,80 +0,0 @@ -# @stylexjs/esbuild-plugin - -Use StyleX with _esbuild_ bundler. - -This plugin transforms files that contain `stylexjs` imports and generates a -`stylexjs` CSS bundle. - -## Installation - -``` -npm install --save-dev @stylexjs/esbuild-plugin -``` - -## Usage - -```typescript -import esbuild from 'esbuild'; -import stylexPlugin from '@stylexjs/esbuild-plugin'; -import path from 'path'; -import { fileURLToPath } from 'url'; - -const __dirname = path.dirname(fileURLToPath(import.meta.url)); - -esbuild.build({ - entryPoints: ['src/index.js'], - bundle: true, - outfile: './build/bundle.js', - minify: true, - plugins: [ - stylexPlugin({ - // If set to 'true', bundler will inject styles in-line - // Do not use in production - dev: false, - // Required. File path for the generated CSS file - generatedCSSFileName: path.resolve(__dirname, 'build/stylex.css'), - // Aliases for StyleX package imports - // default: '@stylexjs/stylex' - stylexImports: ['@stylexjs/stylex'], - // Required for CSS variable support - unstable_moduleResolution: { - // type: 'commonJS' | 'haste' - // default: 'commonJS' - type: 'commonJS', - // The absolute path to the root of your project - rootDir: __dirname, - }, - }), - ], -}); -``` -## Plugin Options -It inherits all options from `@stylexjs/babel-plugin` and can be found [here 🔗](https://stylexjs.com/docs/api/configuration/babel-plugin/). Along with other options like
- -### generatedCSSFileName -```js -generatedCSSFileName: string // Default: 'stylex.css' -``` -The name of the output css file. - ---- -### useCSSLayers -```js -useCSSLayers: boolean // Default: false -``` -Enabling this option switches Stylex from using `:not(#\#)` to using `@layers` for handling CSS specificity. - ---- -### babelConfig -```js -babelConfig: { - plugins: PluginItem[], - presets: PluginItem[] -} // Default: { plugins: [], presets: [] } -``` -List of custom babel plugins and presets which can be used during code transformation. - - ---- -You can see the example usage -[here](https://github.com/facebook/stylex/examples/examples-esbuild). diff --git a/packages/esbuild-plugin/__tests__/__fixtures__/bazStyles.js b/packages/esbuild-plugin/__tests__/__fixtures__/bazStyles.js deleted file mode 100644 index c7fd84f49..000000000 --- a/packages/esbuild-plugin/__tests__/__fixtures__/bazStyles.js +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ - -'use strict'; - -import * as stylex from '@stylexjs/stylex'; - -export default stylex.create({ - baz: { - display: 'block', - height: 900, - width: '50%', - }, -}); diff --git a/packages/esbuild-plugin/__tests__/__fixtures__/fooStyles.js b/packages/esbuild-plugin/__tests__/__fixtures__/fooStyles.js deleted file mode 100644 index daf242dad..000000000 --- a/packages/esbuild-plugin/__tests__/__fixtures__/fooStyles.js +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ - -'use strict'; - -import * as stylex from '@stylexjs/stylex'; - -export default stylex.create({ - foo: { - display: 'inline', - width: '100%', - }, -}); diff --git a/packages/esbuild-plugin/__tests__/__fixtures__/index.js b/packages/esbuild-plugin/__tests__/__fixtures__/index.js deleted file mode 100644 index b6199074c..000000000 --- a/packages/esbuild-plugin/__tests__/__fixtures__/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ - -'use strict'; - -import * as stylex from '@stylexjs/stylex'; -import fooStyles from './fooStyles'; -import bazStyles from './bazStyles'; - -const fadeInAnimation = stylex.keyframes({ - '0%': { - opacity: 0, - }, - '100%': { - opacity: 1, - }, -}); - -const styles = stylex.create({ - bar: { - animationName: fadeInAnimation, - display: 'flex', - marginLeft: 10, - height: 700, - backgroundColor: { - default: 'red', - ':hover': 'pink', - }, - }, -}); - -export default function App() { - return stylex.props(fooStyles.foo, styles.bar, bazStyles.baz); -} diff --git a/packages/esbuild-plugin/__tests__/__fixtures__/index.ts b/packages/esbuild-plugin/__tests__/__fixtures__/index.ts deleted file mode 100644 index 38b2f7768..000000000 --- a/packages/esbuild-plugin/__tests__/__fixtures__/index.ts +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ - -'use strict'; - -import * as stylex from '@stylexjs/stylex'; -import { colors } from './vars.stylex'; - -const styles = stylex.create({ - foo: { - backgroundColor: colors.background, - color: colors.textPrimary, - }, - bar: { - color: colors.textSecondary, - }, -}); - -export default function App() { - return stylex.props(styles.foo, styles.bar); -} diff --git a/packages/esbuild-plugin/__tests__/__fixtures__/vars.stylex.ts b/packages/esbuild-plugin/__tests__/__fixtures__/vars.stylex.ts deleted file mode 100644 index f212536d9..000000000 --- a/packages/esbuild-plugin/__tests__/__fixtures__/vars.stylex.ts +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ - -'use strict'; - -import * as stylex from '@stylexjs/stylex'; - -export const colors = stylex.defineVars({ - background: 'white', - textPrimary: 'pink', - textSecondary: 'green', -}); diff --git a/packages/esbuild-plugin/__tests__/__snapshots__/index-test.js.snap b/packages/esbuild-plugin/__tests__/__snapshots__/index-test.js.snap deleted file mode 100644 index d8a8f0435..000000000 --- a/packages/esbuild-plugin/__tests__/__snapshots__/index-test.js.snap +++ /dev/null @@ -1,220 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`esbuild-plugin-stylex extracts and bundles CSS without inject calls, bundles JS 1`] = ` -""use strict"; -(() => { - var __create = Object.create; - var __defProp = Object.defineProperty; - var __getOwnPropDesc = Object.getOwnPropertyDescriptor; - var __getOwnPropNames = Object.getOwnPropertyNames; - var __getProtoOf = Object.getPrototypeOf; - var __hasOwnProp = Object.prototype.hasOwnProperty; - var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { - get: (a, b) => (typeof require !== "undefined" ? require : a)[b] - }) : x)(function(x) { - if (typeof require !== "undefined") return require.apply(this, arguments); - throw Error('Dynamic require of "' + x + '" is not supported'); - }); - var __copyProps = (to, from, except, desc) => { - if (from && typeof from === "object" || typeof from === "function") { - for (let key of __getOwnPropNames(from)) - if (!__hasOwnProp.call(to, key) && key !== except) - __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); - } - return to; - }; - var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( - // If the importer is in node compatibility mode or this is not an ESM - // file that has been converted to a CommonJS file using a Babel- - // compatible transform (i.e. "__esModule" has not been set), then set - // "default" to the CommonJS "module.exports" for node compatibility. - isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, - mod - )); - - // __tests__/__fixtures__/index.js - var stylex3 = __toESM(__require("@stylexjs/stylex"), 1); - - // __tests__/__fixtures__/fooStyles.js - var stylex = __toESM(__require("@stylexjs/stylex"), 1); - var fooStyles_default = { - foo: { - k1xSpc: "xt0psk2", - kzqmXN: "xh8yej3", - $$css: true - } - }; - - // __tests__/__fixtures__/bazStyles.js - var stylex2 = __toESM(__require("@stylexjs/stylex"), 1); - var bazStyles_default = { - baz: { - k1xSpc: "x1lliihq", - kZKoxP: "xnsd7bc", - kzqmXN: "x3hqpx7", - $$css: true - } - }; - - // __tests__/__fixtures__/index.js - var styles = { - bar: { - kKVMdj: "x127lhb5", - k1xSpc: "x78zum5", - koQZXg: "x16ydxro", - keTefX: null, - k71WvV: null, - kZKoxP: "x1xa6b72", - kWkggS: "xrkmrrc x1r3o6fz", - $$css: true - } - }; - function App() { - return stylex3.props(fooStyles_default.foo, styles.bar, bazStyles_default.baz); - } -})(); -" -`; - -exports[`esbuild-plugin-stylex extracts and bundles CSS without inject calls, bundles JS 2`] = ` -" -@layer priority1, priority2, priority3; -@layer priority1{ -@keyframes xekv6nw-B{0%{opacity:0;}100%{opacity:1;}} -} -@layer priority2{ -.x127lhb5{animation-name:xekv6nw-B} -.xrkmrrc{background-color:red} -.x1lliihq{display:block} -.x78zum5{display:flex} -.xt0psk2{display:inline} -.x1r3o6fz:hover{background-color:pink} -} -@layer priority3{ -.x1xa6b72{height:700px} -.xnsd7bc{height:900px} -.x16ydxro{margin-left:10px} -.xh8yej3{width:100%} -.x3hqpx7{width:50%} -}" -`; - -exports[`esbuild-plugin-stylex extracts and bundles CSS without inject calls, bundles and transforms TS 1`] = ` -""use strict"; -(() => { - // __tests__/__fixtures__/index.ts - function App() { - return { - className: "xktrvhi xthc9sq" - }; - } -})(); -" -`; - -exports[`esbuild-plugin-stylex extracts and bundles CSS without inject calls, bundles and transforms TS 2`] = ` -" -@layer priority1, priority2; -@layer priority1{ -:root, .x1e8sos5{--xx1oc6k:white;--x14p2zvc:pink;--xdr2u03:green;} -} -@layer priority2{ -.xktrvhi{background-color:var(--xx1oc6k)} -.xiz802d{color:var(--x14p2zvc)} -.xthc9sq{color:var(--xdr2u03)} -}" -`; - -exports[`esbuild-plugin-stylex preserves stylex.inject calls and does not extract CSS in development mode 1`] = ` -""use strict"; -(() => { - var __create = Object.create; - var __defProp = Object.defineProperty; - var __getOwnPropDesc = Object.getOwnPropertyDescriptor; - var __getOwnPropNames = Object.getOwnPropertyNames; - var __getProtoOf = Object.getPrototypeOf; - var __hasOwnProp = Object.prototype.hasOwnProperty; - var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { - get: (a, b) => (typeof require !== "undefined" ? require : a)[b] - }) : x)(function(x) { - if (typeof require !== "undefined") return require.apply(this, arguments); - throw Error('Dynamic require of "' + x + '" is not supported'); - }); - var __copyProps = (to, from, except, desc) => { - if (from && typeof from === "object" || typeof from === "function") { - for (let key of __getOwnPropNames(from)) - if (!__hasOwnProp.call(to, key) && key !== except) - __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); - } - return to; - }; - var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( - // If the importer is in node compatibility mode or this is not an ESM - // file that has been converted to a CommonJS file using a Babel- - // compatible transform (i.e. "__esModule" has not been set), then set - // "default" to the CommonJS "module.exports" for node compatibility. - isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, - mod - )); - - // __tests__/__fixtures__/index.js - var import_stylex_inject3 = __toESM(__require("@stylexjs/stylex/lib/stylex-inject"), 1); - var stylex3 = __toESM(__require("@stylexjs/stylex"), 1); - - // __tests__/__fixtures__/fooStyles.js - var import_stylex_inject = __toESM(__require("@stylexjs/stylex/lib/stylex-inject"), 1); - var stylex = __toESM(__require("@stylexjs/stylex"), 1); - var _inject2 = import_stylex_inject.default; - _inject2(".display-xt0psk2{display:inline}", 3e3); - _inject2(".width-xh8yej3{width:100%}", 4e3); - var fooStyles_default = { - foo: { - "display-k1xSpc": "display-xt0psk2", - "width-kzqmXN": "width-xh8yej3", - $$css: "__fixtures__/fooStyles.js:15" - } - }; - - // __tests__/__fixtures__/bazStyles.js - var import_stylex_inject2 = __toESM(__require("@stylexjs/stylex/lib/stylex-inject"), 1); - var stylex2 = __toESM(__require("@stylexjs/stylex"), 1); - var _inject22 = import_stylex_inject2.default; - _inject22(".display-x1lliihq{display:block}", 3e3); - _inject22(".height-xnsd7bc{height:900px}", 4e3); - _inject22(".width-x3hqpx7{width:50%}", 4e3); - var bazStyles_default = { - baz: { - "display-k1xSpc": "display-x1lliihq", - "height-kZKoxP": "height-xnsd7bc", - "width-kzqmXN": "width-x3hqpx7", - $$css: "__fixtures__/bazStyles.js:15" - } - }; - - // __tests__/__fixtures__/index.js - var _inject23 = import_stylex_inject3.default; - _inject23("@keyframes xekv6nw-B{0%{opacity:0;}100%{opacity:1;}}", 1); - _inject23(".animationName-x127lhb5{animation-name:xekv6nw-B}", 3e3); - _inject23(".display-x78zum5{display:flex}", 3e3); - _inject23(".marginLeft-x16ydxro{margin-left:10px}", 4e3); - _inject23(".height-x1xa6b72{height:700px}", 4e3); - _inject23(".backgroundColor-xrkmrrc{background-color:red}", 3e3); - _inject23(".backgroundColor-x1r3o6fz:hover{background-color:pink}", 3130); - var styles = { - bar: { - "animationName-kKVMdj": "animationName-x127lhb5", - "display-k1xSpc": "display-x78zum5", - "marginLeft-koQZXg": "marginLeft-x16ydxro", - "marginInlineStart-keTefX": null, - "marginInlineEnd-k71WvV": null, - "height-kZKoxP": "height-x1xa6b72", - "backgroundColor-kWkggS": "backgroundColor-xrkmrrc backgroundColor-x1r3o6fz", - $$css: "__fixtures__/index.js:26" - } - }; - function App() { - return stylex3.props(fooStyles_default.foo, styles.bar, bazStyles_default.baz); - } -})(); -" -`; diff --git a/packages/esbuild-plugin/__tests__/index-test.js b/packages/esbuild-plugin/__tests__/index-test.js deleted file mode 100644 index 24eed423e..000000000 --- a/packages/esbuild-plugin/__tests__/index-test.js +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * - */ - -'use strict'; - -import path from 'path'; -import esbuild from 'esbuild'; -import stylexPlugin from '../src/index'; - -async function build(options = {}) { - const { isTS, ...rest } = options; - - const { outputFiles } = await esbuild.build({ - entryPoints: [ - path.resolve(__dirname, `__fixtures__/index.${isTS ? 'ts' : 'js'}`), - ], - external: ['@stylexjs/stylex'], - minify: false, - bundle: true, - write: false, - plugins: [stylexPlugin({ useCSSLayers: true, ...rest })], - }); - - return { js: outputFiles[0], css: outputFiles[1] }; -} - -describe('esbuild-plugin-stylex', () => { - it('extracts and bundles CSS without inject calls, bundles JS', async () => { - const { js, css } = await build(); - - expect(js.text).toMatchSnapshot(); - - expect(css.text).toMatchSnapshot(); - }); - - it('extracts and bundles CSS without inject calls, bundles and transforms TS', async () => { - const { js, css } = await build({ isTS: true }); - - expect(js.text).toMatchSnapshot(); - - expect(css.text).toMatchSnapshot(); - }); - - it('preserves stylex.inject calls and does not extract CSS in development mode', async () => { - const { js, css } = await build({ dev: true }); - - expect(js.text).toMatchSnapshot(); - - expect(css).toBeUndefined(); - }); -}); diff --git a/packages/esbuild-plugin/flow_modules/@babel/core/index.js.flow b/packages/esbuild-plugin/flow_modules/@babel/core/index.js.flow deleted file mode 100644 index 018730f86..000000000 --- a/packages/esbuild-plugin/flow_modules/@babel/core/index.js.flow +++ /dev/null @@ -1,854 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @flow strict - */ - -import type { GeneratorOptions as _GeneratorOptions } from '../generator'; -import type { - ParserOptions as _ParserOptions, - ParseResult as _ParseResult, -} from '../parser'; -import traverse, { - Hub, - NodePath, - Scope, - type Visitor as _Visitor, -} from '../traverse'; -import * as t from '../types'; -export * as types from '../types'; - -export type GeneratorOptions = _GeneratorOptions; -export type ParserOptions = _ParserOptions; - -export { traverse, NodePath }; - -export type Visitor = _Visitor; - -export type Node = t.Node; -export type ParseResult = _ParseResult; -declare export var version: string; -declare export var DEFAULT_EXTENSIONS: ['.js', '.jsx', '.es6', '.es', '.mjs']; - -interface InputSourceMap { - version: number; - sources: Array; - names: Array; - sourceRoot?: string | void; - sourcesContent?: Array | void; - mappings: string; - file: string; -} - -export interface TransformOptions { - /** - * Include the AST in the returned object - * - * Default: `false` - */ - ast?: ?boolean; - - /** - * Attach a comment after all non-user injected code - * - * Default: `null` - */ - auxiliaryCommentAfter?: ?string; - - /** - * Attach a comment before all non-user injected code - * - * Default: `null` - */ - auxiliaryCommentBefore?: ?string; - - /** - * Specify the "root" folder that defines the location to search for "babel.config.js", and the default folder to allow `.babelrc` files inside of. - * - * Default: `"."` - */ - root?: ?string; - - /** - * This option, combined with the "root" value, defines how Babel chooses its project root. - * The different modes define different ways that Babel can process the "root" value to get - * the final project root. - * - * @see https://babeljs.io/docs/en/next/options#rootmode - */ - rootMode?: 'root' | 'upward' | 'upward-optional' | void; - - /** - * The config file to load Babel's config from. Defaults to searching for "babel.config.js" inside the "root" folder. `false` will disable searching for config files. - * - * Default: `undefined` - */ - configFile?: ?string | boolean; - - /** - * Specify whether or not to use .babelrc and - * .babelignore files. - * - * Default: `true` - */ - babelrc?: ?boolean; - - /** - * Specify which packages should be search for .babelrc files when they are being compiled. `true` to always search, or a path string or an array of paths to packages to search - * inside of. Defaults to only searching the "root" package. - * - * Default: `(root)` - */ - babelrcRoots?: ?boolean | MatchPattern | Array; - - /** - * Toggles whether or not browserslist config sources are used, which includes searching for any browserslist files or referencing the browserslist key inside package.json. - * This is useful for projects that use a browserslist config for files that won't be compiled with Babel. - * - * If a string is specified, it must represent the path of a browserslist configuration file. Relative paths are resolved relative to the configuration file which specifies - * this option, or to `cwd` when it's passed as part of the programmatic options. - * - * Default: `true` - */ - browserslistConfigFile?: ?boolean; - - /** - * The Browserslist environment to use. - * - * Default: `undefined` - */ - browserslistEnv?: ?string; - - /** - * By default `babel.transformFromAst` will clone the input AST to avoid mutations. - * Specifying `cloneInputAst: false` can improve parsing performance if the input AST is not used elsewhere. - * - * Default: `true` - */ - cloneInputAst?: ?boolean; - - /** - * Defaults to environment variable `BABEL_ENV` if set, or else `NODE_ENV` if set, or else it defaults to `"development"` - * - * Default: env vars - */ - envName?: string | void; - - /** - * If any of patterns match, the current configuration object is considered inactive and is ignored during config processing. - */ - exclude?: MatchPattern | Array | void; - - /** - * Enable code generation - * - * Default: `true` - */ - code?: ?boolean; - - /** - * Output comments in generated output - * - * Default: `true` - */ - comments?: ?boolean; - - /** - * Do not include superfluous whitespace characters and line terminators. When set to `"auto"` compact is set to `true` on input sizes of >500KB - * - * Default: `"auto"` - */ - compact?: boolean | 'auto' | null | void; - - /** - * The working directory that Babel's programmatic options are loaded relative to. - * - * Default: `"."` - */ - cwd?: ?string; - - /** - * Utilities may pass a caller object to identify themselves to Babel and - * pass capability-related flags for use by configs, presets and plugins. - * - * @see https://babeljs.io/docs/en/next/options#caller - */ - caller?: TransformCaller | void; - - /** - * This is an object of keys that represent different environments. For example, you may have: `{ env: { production: { \/* specific options *\/ } } }` - * which will use those options when the `envName` is `production` - * - * Default: `{}` - */ - env?: ?{ [index: string]: ?TransformOptions }; - - /** - * A path to a `.babelrc` file to extend - * - * Default: `null` - */ - extends?: ?string; - - /** - * Filename for use in errors etc - * - * Default: `"unknown"` - */ - filename?: ?string; - - /** - * Filename relative to `sourceRoot` - * - * Default: `(filename)` - */ - filenameRelative?: ?string; - - /** - * An object containing the options to be passed down to the babel code generator, @babel/generator - * - * Default: `{}` - */ - generatorOpts?: ?GeneratorOptions; - - /** - * Specify a custom callback to generate a module id with. Called as `getModuleId(moduleName)`. If falsy value is returned then the generated module id is used - * - * Default: `null` - */ - getModuleId?: ?(moduleName: string) => ?string; - - /** - * ANSI highlight syntax error code frames - * - * Default: `true` - */ - highlightCode?: ?boolean; - - /** - * Opposite to the `only` option. `ignore` is disregarded if `only` is specified - * - * Default: `null` - */ - ignore?: ?Array; - - /** - * This option is a synonym for "test" - */ - include?: MatchPattern | Array | void; - - /** - * A source map object that the output source map will be based on - * - * Default: `null` - */ - inputSourceMap?: ?InputSourceMap; - - /** - * Should the output be minified (not printing last semicolons in blocks, printing literal string values instead of escaped ones, stripping `()` from `new` when safe) - * - * Default: `false` - */ - minified?: ?boolean; - - /** - * Specify a custom name for module ids - * - * Default: `null` - */ - moduleId?: ?string; - - /** - * If truthy, insert an explicit id for modules. By default, all modules are anonymous. (Not available for `common` modules) - * - * Default: `false` - */ - moduleIds?: ?boolean; - - /** - * Optional prefix for the AMD module formatter that will be prepend to the filename on module definitions - * - * Default: `(sourceRoot)` - */ - moduleRoot?: ?string; - - /** - * A glob, regex, or mixed array of both, matching paths to **only** compile. Can also be an array of arrays containing paths to explicitly match. When attempting to compile - * a non-matching file it's returned verbatim - * - * Default: `null` - */ - only?: ?Array; - - /** - * Allows users to provide an array of options that will be merged into the current configuration one at a time. - * This feature is best used alongside the "test"/"include"/"exclude" options to provide conditions for which an override should apply - */ - overrides?: TransformOptions[] | void; - - /** - * An object containing the options to be passed down to the babel parser, @babel/parser - * - * Default: `{}` - */ - parserOpts?: ?ParserOptions; - - /** - * List of plugins to load and use - * - * Default: `[]` - */ - plugins?: ?$ReadOnlyArray; - - /** - * List of presets (a set of plugins) to load and use - * - * Default: `[]` - */ - presets?: ?$ReadOnlyArray; - - /** - * Retain line numbers. This will lead to wacky code but is handy for scenarios where you can't use source maps. (**NOTE**: This will not retain the columns) - * - * Default: `false` - */ - retainLines?: ?boolean; - - /** - * An optional callback that controls whether a comment should be output or not. Called as `shouldPrintComment(commentContents)`. **NOTE**: This overrides the `comment` option when used - * - * Default: `null` - */ - shouldPrintComment?: ?(commentContents: string) => boolean; - - /** - * Set `sources[0]` on returned source map - * - * Default: `(filenameRelative)` - */ - sourceFileName?: ?string; - - /** - * If truthy, adds a `map` property to returned output. If set to `"inline"`, a comment with a sourceMappingURL directive is added to the bottom of the returned code. If set to `"both"` - * then a `map` property is returned as well as a source map comment appended. **This does not emit sourcemap files by itself!** - * - * Default: `false` - */ - sourceMaps?: ?boolean | 'inline' | 'both'; - - /** - * The root from which all sources are relative - * - * Default: `(moduleRoot)` - */ - sourceRoot?: ?string; - - /** - * Indicate the mode the code should be parsed in. Can be one of "script", "module", or "unambiguous". `"unambiguous"` will make Babel attempt to guess, based on the presence of ES6 - * `import` or `export` statements. Files with ES6 `import`s and `export`s are considered `"module"` and are otherwise `"script"`. - * - * Default: `("module")` - */ - sourceType?: ?'script' | 'module' | 'unambiguous'; - - /** - * If all patterns fail to match, the current configuration object is considered inactive and is ignored during config processing. - */ - test?: MatchPattern | Array | void; - - /** - * An optional callback that can be used to wrap visitor methods. **NOTE**: This is useful for things like introspection, and not really needed for implementing anything. Called as - * `wrapPluginVisitorMethod(pluginAlias, visitorType, callback)`. - */ - wrapPluginVisitorMethod?: - | (( - pluginAlias: string, - visitorType: 'enter' | 'exit', - callback: (path: NodePath<>, state: any) => void, - ) => (path: NodePath<>, state: any) => void) - | null - | void; -} - -export interface TransformCaller { - // the only required property - name: string; - // e.g. set to true by `babel-loader` and false by `babel-jest` - supportsStaticESM?: boolean | void; - supportsDynamicImport?: boolean | void; - supportsExportNamespaceFrom?: boolean | void; - supportsTopLevelAwait?: boolean | void; - // augment this with a "declare module '@babel/core' { ... }" if you need more keys -} - -export type FileResultCallback = ( - err: Error | null, - result: BabelFileResult | null, -) => any; - -export interface MatchPatternContext { - envName: string; - dirname: string; - caller: TransformCaller | void; -} - -export type MatchPattern = - | string - | RegExp - | ((filename: string | void, context: MatchPatternContext) => boolean); - -/** - * Transforms the passed in code. Calling a callback with an object with the generated code, source map, and AST. - */ -declare export var transform: (( - code: string, - callback: FileResultCallback, -) => void) & - (( - code: string, - opts: ?TransformOptions, - callback: FileResultCallback, - ) => void); - -/** - * Transforms the passed in code. Returning an object with the generated code, source map, and AST. - */ -declare export function transformSync( - code: string, - opts?: TransformOptions, -): BabelFileResult | null; - -/** - * Transforms the passed in code. Calling a callback with an object with the generated code, source map, and AST. - */ -declare export function transformAsync( - code: string, - opts?: TransformOptions, -): Promise; - -/** - * Asynchronously transforms the entire contents of a file. - */ -declare export var transformFile: (( - filename: string, - callback: FileResultCallback, -) => void) & - (( - filename: string, - opts: ?TransformOptions, - callback: FileResultCallback, - ) => void); - -/** - * Synchronous version of `babel.transformFile`. Returns the transformed contents of the `filename`. - */ -declare export function transformFileSync( - filename: string, - opts?: TransformOptions, -): BabelFileResult | null; - -/** - * Asynchronously transforms the entire contents of a file. - */ -declare export function transformFileAsync( - filename: string, - opts?: TransformOptions, -): Promise; - -/** - * Given an AST, transform it. - */ -declare export var transformFromAst: (( - ast: Node, - code: string | void, - callback: FileResultCallback, -) => void) & - (( - ast: Node, - code: string | void, - opts: TransformOptions | void, - callback: FileResultCallback, - ) => void); - -/** - * Here for backward-compatibility. Ideally use ".transformSync" if you want a synchronous API. - */ -declare export function transformFromAstSync( - ast: Node, - code?: string, - opts?: TransformOptions, -): BabelFileResult | null; - -/** - * Given an AST, transform it. - */ -declare export function transformFromAstAsync( - ast: Node, - code?: string, - opts?: TransformOptions, -): Promise; - -// A babel plugin is a simple function which must return an object matching -// the following interface. Babel will throw if it finds unknown properties. -// The list of allowed plugin keys is here: -// https://github.com/babel/babel/blob/4e50b2d9d9c376cee7a2cbf56553fe5b982ea53c/packages/babel-core/src/config/option-manager.js#L71 -export interface PluginObj { - +name?: string | void; - +manipulateOptions?: (opts: any, parserOpts: any) => void; - +pre?: (this: S, file: BabelFile) => void; - +visitor: Visitor; - +post?: (this: S, file: BabelFile) => void; - +inherits?: any; -} - -export interface BabelFile { - ast: t.File; - opts: TransformOptions; - hub: Hub; - metadata: { [string]: mixed }; - path: NodePath; - scope: Scope; - inputMap: { [string]: mixed } | null; - code: string; -} - -export interface PluginPass { - file: BabelFile; - key: string; - opts: { [string]: mixed }; - cwd: string; - filename: string | void; - get(key: mixed): any; - set(key: mixed, value: mixed): void; - [key: string]: mixed; -} - -export interface BabelFileResult { - ast?: ?t.File; - code?: ?string; - ignored?: boolean | void; - map?: ?{ - version: number, - sources: Array, - names: Array, - sourceRoot?: string | void, - sourcesContent?: Array | void, - mappings: string, - file: string, - }; - metadata?: BabelFileMetadata | void; -} - -export interface BabelFileMetadata { - usedHelpers: string[]; - marked: Array<{ - type: string, - message: string, - loc: { [string]: mixed }, - }>; - modules: BabelFileModulesMetadata; -} - -export interface BabelFileModulesMetadata { - imports: Array<{ [string]: mixed }>; - exports: { - exported: Array<{ [string]: mixed }>, - specifiers: Array<{ [string]: mixed }>, - }; -} - -export type FileParseCallback = ( - err: Error | null, - result: ParseResult<> | null, -) => any; - -/** - * Given some code, parse it using Babel's standard behavior. - * Referenced presets and plugins will be loaded such that optional syntax plugins are automatically enabled. - */ -declare export var parse: (( - code: string, - callback: FileParseCallback, -) => void) & - (( - code: string, - options: TransformOptions | void, - callback: FileParseCallback, - ) => void); - -/** - * Given some code, parse it using Babel's standard behavior. - * Referenced presets and plugins will be loaded such that optional syntax plugins are automatically enabled. - */ -declare export function parseSync( - code: string, - options?: TransformOptions, -): ParseResult | null; - -/** - * Given some code, parse it using Babel's standard behavior. - * Referenced presets and plugins will be loaded such that optional syntax plugins are automatically enabled. - */ -declare export function parseAsync( - code: string, - options?: TransformOptions, -): Promise | null>; - -/** - * Resolve Babel's options fully, resulting in an options object where: - * - * * opts.plugins is a full list of Plugin instances. - * * opts.presets is empty and all presets are flattened into opts. - * * It can be safely passed back to Babel. Fields like babelrc have been set to false so that later calls to Babel - * will not make a second attempt to load config files. - * - * Plugin instances aren't meant to be manipulated directly, but often callers will serialize this opts to JSON to - * use it as a cache key representing the options Babel has received. Caching on this isn't 100% guaranteed to - * invalidate properly, but it is the best we have at the moment. - */ -declare export function loadOptions( - options?: TransformOptions, -): { [string]: mixed } | null; - -/** - * To allow systems to easily manipulate and validate a user's config, this function resolves the plugins and - * presets and proceeds no further. The expectation is that callers will take the config's .options, manipulate it - * as then see fit and pass it back to Babel again. - * - * * `babelrc: string | void` - The path of the `.babelrc` file, if there was one. - * * `babelignore: string | void` - The path of the `.babelignore` file, if there was one. - * * `options: ValidatedOptions` - The partially resolved options, which can be manipulated and passed back - * to Babel again. - * * `plugins: Array` - See below. - * * `presets: Array` - See below. - * * It can be safely passed back to Babel. Fields like `babelrc` have been set to false so that later calls to - * Babel will not make a second attempt to load config files. - * - * `ConfigItem` instances expose properties to introspect the values, but each item should be treated as - * immutable. If changes are desired, the item should be removed from the list and replaced with either a normal - * Babel config value, or with a replacement item created by `babel.createConfigItem`. See that function for - * information about `ConfigItem` fields. - */ -declare export function loadPartialConfig( - options?: TransformOptions, -): $ReadOnly | null; -declare export function loadPartialConfigAsync( - options?: TransformOptions, -): Promise<$ReadOnly | null>; - -export interface PartialConfig { - options: TransformOptions; - babelrc?: string | void; - babelignore?: string | void; - config?: string | void; - hasFilesystemConfig: () => boolean; -} - -export interface ConfigItem { - /** - * The name that the user gave the plugin instance, e.g. `plugins: [ ['env', {}, 'my-env'] ]` - */ - name?: string | void; - - /** - * The resolved value of the plugin. - */ - value: { [string]: mixed } | ((...args: any[]) => any); - - /** - * The options object passed to the plugin. - */ - options?: { [string]: mixed } | false | void; - - /** - * The path that the options are relative to. - */ - dirname: string; - - /** - * Information about the plugin's file, if Babel knows it. - * * - */ - file?: ?{ - /** - * The file that the user requested, e.g. `"@babel/env"` - */ - request: string, - - /** - * The full path of the resolved file, e.g. `"/tmp/node_modules/@babel/preset-env/lib/index.js"` - */ - resolved: string, - }; -} - -export type PluginOptions = $ReadOnly<{ [string]: mixed }> | void | false; - -export type PluginTarget = - | string - | $ReadOnly<{ [string]: mixed }> - | ((...args: any[]) => any); - -export type PluginItem = - | ConfigItem - | PluginObj - | PluginTarget - | $ReadOnly<[PluginTarget, PluginOptions]> - | $ReadOnly<[PluginTarget, PluginOptions, string | void]>; - -declare export function resolvePlugin( - name: string, - dirname: string, -): string | null; -declare export function resolvePreset( - name: string, - dirname: string, -): string | null; - -export interface CreateConfigItemOptions { - dirname?: string | void; - type?: 'preset' | 'plugin' | void; -} - -/** - * Allows build tooling to create and cache config items up front. If this function is called multiple times for a - * given plugin, Babel will call the plugin's function itself multiple times. If you have a clear set of expected - * plugins and presets to inject, pre-constructing the config items would be recommended. - */ -declare export function createConfigItem( - value: - | PluginTarget - | [PluginTarget, PluginOptions] - | [PluginTarget, PluginOptions, string | void], - options?: CreateConfigItemOptions, -): ConfigItem; - -/** - * @see https://babeljs.io/docs/en/next/config-files#config-function-api - */ -export interface ConfigAPI { - /** - * The version string for the Babel version that is loading the config file. - * - * @see https://babeljs.io/docs/en/next/config-files#apiversion - */ - version: string; - /** - * @see https://babeljs.io/docs/en/next/config-files#apicache - */ - cache: SimpleCacheConfigurator; - /** - * @see https://babeljs.io/docs/en/next/config-files#apienv - */ - env: EnvFunction; - // undocumented; currently hardcoded to return 'false' - // async(): boolean - /** - * This API is used as a way to access the `caller` data that has been passed to Babel. - * Since many instances of Babel may be running in the same process with different `caller` values, - * this API is designed to automatically configure `api.cache`, the same way `api.env()` does. - * - * The `caller` value is available as the first parameter of the callback function. - * It is best used with something like this to toggle configuration behavior - * based on a specific environment: - * - * @example - * function isBabelRegister(caller?: { name: string }) { - * return !!(caller && caller.name === "@babel/register") - * } - * api.caller(isBabelRegister) - * - * @see https://babeljs.io/docs/en/next/config-files#apicallercb - */ - caller( - callerCallback: (caller: TransformOptions['caller']) => T, - ): T; - /** - * While `api.version` can be useful in general, it's sometimes nice to just declare your version. - * This API exposes a simple way to do that with: - * - * @example - * api.assertVersion(7) // major version only - * api.assertVersion("^7.2") - * - * @see https://babeljs.io/docs/en/next/config-files#apiassertversionrange - */ - assertVersion(versionRange: number | string): boolean; - // NOTE: this is an undocumented reexport from "@babel/parser" but it's missing from its types - // tokTypes: typeof tokTypes -} - -/** - * JS configs are great because they can compute a config on the fly, - * but the downside there is that it makes caching harder. - * Babel wants to avoid re-executing the config function every time a file is compiled, - * because then it would also need to re-execute any plugin and preset functions - * referenced in that config. - * - * To avoid this, Babel expects users of config functions to tell it how to manage caching - * within a config file. - * - * @see https://babeljs.io/docs/en/next/config-files#apicache - */ -export interface SimpleCacheConfigurator { - // there is an undocumented call signature that is a shorthand for forever()/never()/using(). - // (ever: boolean): void - // (callback: CacheCallback): T - /** - * Permacache the computed config and never call the function again. - */ - forever(): void; - /** - * Do not cache this config, and re-execute the function every time. - */ - never(): void; - /** - * Any time the using callback returns a value other than the one that was expected, - * the overall config function will be called again and a new entry will be added to the cache. - * - * @example - * api.cache.using(() => process.env.NODE_ENV) - */ - using(callback: SimpleCacheCallback): T; - /** - * Any time the using callback returns a value other than the one that was expected, - * the overall config function will be called again and all entries in the cache will - * be replaced with the result. - * - * @example - * api.cache.invalidate(() => process.env.NODE_ENV) - */ - invalidate(callback: SimpleCacheCallback): T; -} - -// https://github.com/babel/babel/blob/v7.3.3/packages/babel-core/src/config/caching.js#L231 -export type SimpleCacheKey = ?string | boolean | number; -export type SimpleCacheCallback = () => T; - -/** - * Since `NODE_ENV` is a fairly common way to toggle behavior, Babel also includes an API function - * meant specifically for that. This API is used as a quick way to check the `"envName"` that Babel - * was loaded with, which takes `NODE_ENV` into account if no other overriding environment is set. - * - * @see https://babeljs.io/docs/en/next/config-files#apienv - */ -export type EnvFunction = - /** - * @returns the current `envName` string - */ - (() => string) & - /** - * @returns `true` if the `envName` is `===` any of the given strings - */ - ((envName: string | $ReadOnlyArray) => boolean) & - // the official documentation is misleading for this one... - // this just passes the callback to `cache.using` but with an additional argument. - // it returns its result instead of necessarily returning a boolean. - (( - envCallback: (envName: $NonMaybeType) => T, - ) => T); - -export type ConfigFunction = (api: ConfigAPI) => TransformOptions; diff --git a/packages/esbuild-plugin/flow_modules/@babel/generator/index.js.flow b/packages/esbuild-plugin/flow_modules/@babel/generator/index.js.flow deleted file mode 100644 index 099edf384..000000000 --- a/packages/esbuild-plugin/flow_modules/@babel/generator/index.js.flow +++ /dev/null @@ -1,216 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * @flow strict - */ - -import * as t from '../types'; - -export interface GeneratorOptions { - /** - * Optional string to add as a block comment at the start of the output file. - */ - +auxiliaryCommentBefore?: string | void; - - /** - * Optional string to add as a block comment at the end of the output file. - */ - +auxiliaryCommentAfter?: string | void; - - /** - * Function that takes a comment (as a string) and returns true if the comment should be included in the output. - * By default, comments are included if `opts.comments` is `true` or if `opts.minifed` is `false` and the comment - * contains `@preserve` or `@license`. - */ - +shouldPrintComment?: (comment: string) => boolean; - - /** - * Attempt to use the same line numbers in the output code as in the source code (helps preserve stack traces). - * Defaults to `false`. - */ - +retainLines?: boolean | void; - - /** - * Retain parens around function expressions (could be used to change engine parsing behavior) - * Defaults to `false`. - */ - +retainFunctionParens?: boolean | void; - - /** - * Should comments be included in output? Defaults to `true`. - */ - comments?: boolean | void; - - /** - * Set to true to avoid adding whitespace for formatting. Defaults to the value of `opts.minified`. - */ - compact?: boolean | 'auto' | void; - - /** - * Should the output be minified. Defaults to `false`. - */ - minified?: boolean | void; - - /** - * Set to true to reduce whitespace (but not as much as opts.compact). Defaults to `false`. - */ - concise?: boolean | void; - - /** - * Used in warning messages - */ - filename?: string | void; - - /** - * Enable generating source maps. Defaults to `false`. - */ - sourceMaps?: boolean | void; - - /** - * A root for all relative URLs in the source map. - */ - sourceRoot?: string | void; - - /** - * The filename for the source code (i.e. the code in the `code` argument). - * This will only be used if `code` is a string. - */ - sourceFileName?: string | void; - - /** - * Set to true to run jsesc with "json": true to print "\u00A9" vs. "©"; - */ - jsonCompatibleStrings?: boolean | void; - - /** - * Set to true to enable support for experimental decorators syntax before module exports. - * Defaults to `false`. - */ - decoratorsBeforeExport?: boolean | void; - - /** - * Options for outputting jsesc representation. - */ - jsescOption?: { - /** - * The default value for the quotes option is 'single'. This means that any occurrences of ' in the input - * string are escaped as \', so that the output can be used in a string literal wrapped in single quotes. - */ - quotes?: 'single' | 'double' | 'backtick' | void, - - /** - * The default value for the numbers option is 'decimal'. This means that any numeric values are represented - * using decimal integer literals. Other valid options are binary, octal, and hexadecimal, which result in - * binary integer literals, octal integer literals, and hexadecimal integer literals, respectively. - */ - numbers?: 'binary' | 'octal' | 'decimal' | 'hexadecimal' | void, - - /** - * The wrap option takes a boolean value (true or false), and defaults to false (disabled). When enabled, the - * output is a valid JavaScript string literal wrapped in quotes. The type of quotes can be specified through - * the quotes setting. - */ - wrap?: boolean | void, - - /** - * The es6 option takes a boolean value (true or false), and defaults to false (disabled). When enabled, any - * astral Unicode symbols in the input are escaped using ECMAScript 6 Unicode code point escape sequences - * instead of using separate escape sequences for each surrogate half. If backwards compatibility with ES5 - * environments is a concern, don’t enable this setting. If the json setting is enabled, the value for the es6 - * setting is ignored (as if it was false). - */ - es6?: boolean | void, - - /** - * The escapeEverything option takes a boolean value (true or false), and defaults to false (disabled). When - * enabled, all the symbols in the output are escaped — even printable ASCII symbols. - */ - escapeEverything?: boolean | void, - - /** - * The minimal option takes a boolean value (true or false), and defaults to false (disabled). When enabled, - * only a limited set of symbols in the output are escaped: \0, \b, \t, \n, \f, \r, \\, \u2028, \u2029. - */ - minimal?: boolean | void, - - /** - * The isScriptContext option takes a boolean value (true or false), and defaults to false (disabled). When - * enabled, occurrences of or