@stylexjs/rollup-plugin 0.6.1 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc.cjs +4 -1
- package/package.json +13 -5
- package/src/index.js +36 -2
- package/lib/index.d.ts +0 -34
- package/lib/index.js +0 -93
- package/lib/index.js.flow +0 -25
package/.babelrc.cjs
CHANGED
|
@@ -8,7 +8,10 @@ module.exports = {
|
|
|
8
8
|
{
|
|
9
9
|
exclude: ['@babel/plugin-transform-typeof-symbol'],
|
|
10
10
|
targets: 'defaults',
|
|
11
|
-
modules:
|
|
11
|
+
modules:
|
|
12
|
+
process.env.NODE_ENV === 'test' || process.env.BABEL_ENV === 'cjs'
|
|
13
|
+
? 'commonjs'
|
|
14
|
+
: false,
|
|
12
15
|
},
|
|
13
16
|
],
|
|
14
17
|
'@babel/preset-flow',
|
package/package.json
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stylexjs/rollup-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Rollup plugin for StyleX",
|
|
5
|
-
"main": "lib/index.js",
|
|
6
|
-
"
|
|
5
|
+
"main": "./lib/index.js",
|
|
6
|
+
"module": "./lib/es/index.mjs",
|
|
7
|
+
"types": "./lib/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
"import": "./lib/es/index.mjs",
|
|
10
|
+
"require": "./lib/index.js",
|
|
11
|
+
"types": "./lib/index.d.ts"
|
|
12
|
+
},
|
|
7
13
|
"repository": "https://www.github.com/facebook/stylex",
|
|
8
14
|
"license": "MIT",
|
|
9
15
|
"scripts": {
|
|
10
16
|
"prebuild": "gen-types -i src/ -o lib/",
|
|
11
|
-
"build": "babel src/ --out-dir lib/ --copy-files",
|
|
17
|
+
"build:cjs": "cross-env BABEL_ENV=cjs babel src/ --out-dir lib/ --copy-files",
|
|
18
|
+
"build:esm": "cross-env BABEL_ENV=esm babel src/ --out-dir lib/es --out-file-extension .mjs",
|
|
19
|
+
"build": "npm run build:cjs && npm run build:esm",
|
|
12
20
|
"test": "jest"
|
|
13
21
|
},
|
|
14
22
|
"jest": {
|
|
@@ -21,7 +29,7 @@
|
|
|
21
29
|
},
|
|
22
30
|
"dependencies": {
|
|
23
31
|
"@babel/core": "^7.23.9",
|
|
24
|
-
"@stylexjs/babel-plugin": "0.
|
|
32
|
+
"@stylexjs/babel-plugin": "0.7.1",
|
|
25
33
|
"@babel/plugin-syntax-flow": "^7.23.3",
|
|
26
34
|
"@babel/plugin-syntax-jsx": "^7.23.3",
|
|
27
35
|
"@babel/plugin-syntax-typescript": "^7.23.3"
|
package/src/index.js
CHANGED
|
@@ -14,7 +14,12 @@ import jsxSyntaxPlugin from '@babel/plugin-syntax-jsx';
|
|
|
14
14
|
import typescriptSyntaxPlugin from '@babel/plugin-syntax-typescript';
|
|
15
15
|
import path from 'path';
|
|
16
16
|
import type { Options, Rule } from '@stylexjs/babel-plugin';
|
|
17
|
-
import type {
|
|
17
|
+
import type {
|
|
18
|
+
Plugin,
|
|
19
|
+
PluginContext,
|
|
20
|
+
TransformResult,
|
|
21
|
+
TransformPluginContext,
|
|
22
|
+
} from 'rollup';
|
|
18
23
|
|
|
19
24
|
const IS_DEV_ENV =
|
|
20
25
|
process.env.NODE_ENV === 'development' ||
|
|
@@ -67,7 +72,11 @@ export default function stylexPlugin({
|
|
|
67
72
|
stylexRules[id] = meta.stylex;
|
|
68
73
|
return false;
|
|
69
74
|
},
|
|
70
|
-
async transform(
|
|
75
|
+
async transform(
|
|
76
|
+
this: TransformPluginContext,
|
|
77
|
+
inputCode: string,
|
|
78
|
+
id: string,
|
|
79
|
+
): Promise<null | TransformResult> {
|
|
71
80
|
if (
|
|
72
81
|
!importSources.some((importName) =>
|
|
73
82
|
typeof importName === 'string'
|
|
@@ -96,6 +105,13 @@ export default function stylexPlugin({
|
|
|
96
105
|
unstable_moduleResolution,
|
|
97
106
|
}),
|
|
98
107
|
],
|
|
108
|
+
caller: {
|
|
109
|
+
name: '@stylexjs/rollup-plugin',
|
|
110
|
+
supportsStaticESM: true,
|
|
111
|
+
supportsDynamicImport: true,
|
|
112
|
+
supportsTopLevelAwait: !inputCode.includes('require('),
|
|
113
|
+
supportsExportNamespaceFrom: true,
|
|
114
|
+
},
|
|
99
115
|
});
|
|
100
116
|
if (result == null) {
|
|
101
117
|
console.warn('stylex: transformAsync returned null');
|
|
@@ -107,6 +123,24 @@ export default function stylexPlugin({
|
|
|
107
123
|
return { code: inputCode };
|
|
108
124
|
}
|
|
109
125
|
|
|
126
|
+
// $FlowExpectedError[object-this-reference]
|
|
127
|
+
const self = this;
|
|
128
|
+
|
|
129
|
+
if (self.meta.watchMode) {
|
|
130
|
+
const ast = self.parse(code);
|
|
131
|
+
for (const stmt of ast.body) {
|
|
132
|
+
if (stmt.type === 'ImportDeclaration') {
|
|
133
|
+
const resolved = await self.resolve(stmt.source.value, id);
|
|
134
|
+
if (resolved && !resolved.external) {
|
|
135
|
+
const result = await self.load(resolved);
|
|
136
|
+
if (result && result.meta && 'stylex' in result.meta) {
|
|
137
|
+
stylexRules[resolved.id] = result.meta.stylex;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
110
144
|
if (
|
|
111
145
|
!dev &&
|
|
112
146
|
(metadata as $FlowFixMe).stylex != null &&
|
package/lib/index.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { type PluginItem } from '@babel/core';
|
|
11
|
-
import type { Options } from '@stylexjs/babel-plugin';
|
|
12
|
-
import type { Plugin } from 'rollup';
|
|
13
|
-
export type PluginOptions = Readonly<
|
|
14
|
-
Omit<
|
|
15
|
-
Partial<Options>,
|
|
16
|
-
keyof ({
|
|
17
|
-
fileName?: string;
|
|
18
|
-
babelConfig?: Readonly<{
|
|
19
|
-
plugins?: ReadonlyArray<PluginItem>;
|
|
20
|
-
presets?: ReadonlyArray<PluginItem>;
|
|
21
|
-
}>;
|
|
22
|
-
useCSSLayers?: boolean;
|
|
23
|
-
})
|
|
24
|
-
> & {
|
|
25
|
-
fileName?: string;
|
|
26
|
-
babelConfig?: Readonly<{
|
|
27
|
-
plugins?: ReadonlyArray<PluginItem>;
|
|
28
|
-
presets?: ReadonlyArray<PluginItem>;
|
|
29
|
-
}>;
|
|
30
|
-
useCSSLayers?: boolean;
|
|
31
|
-
}
|
|
32
|
-
>;
|
|
33
|
-
declare function stylexPlugin($$PARAM_0$$: PluginOptions): Plugin;
|
|
34
|
-
export default stylexPlugin;
|
package/lib/index.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { transformAsync } from '@babel/core';
|
|
2
|
-
import stylexBabelPlugin from '@stylexjs/babel-plugin';
|
|
3
|
-
import flowSyntaxPlugin from '@babel/plugin-syntax-flow';
|
|
4
|
-
import jsxSyntaxPlugin from '@babel/plugin-syntax-jsx';
|
|
5
|
-
import typescriptSyntaxPlugin from '@babel/plugin-syntax-typescript';
|
|
6
|
-
import path from 'path';
|
|
7
|
-
const IS_DEV_ENV = process.env.NODE_ENV === 'development' || process.env.BABEL_ENV === 'development';
|
|
8
|
-
export default function stylexPlugin() {
|
|
9
|
-
let {
|
|
10
|
-
dev = IS_DEV_ENV,
|
|
11
|
-
unstable_moduleResolution = {
|
|
12
|
-
type: 'commonJS',
|
|
13
|
-
rootDir: process.cwd()
|
|
14
|
-
},
|
|
15
|
-
fileName = 'stylex.css',
|
|
16
|
-
babelConfig: {
|
|
17
|
-
plugins = [],
|
|
18
|
-
presets = []
|
|
19
|
-
} = {},
|
|
20
|
-
importSources = ['stylex', '@stylexjs/stylex'],
|
|
21
|
-
useCSSLayers = false,
|
|
22
|
-
...options
|
|
23
|
-
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
24
|
-
let stylexRules = {};
|
|
25
|
-
return {
|
|
26
|
-
name: 'rollup-plugin-stylex',
|
|
27
|
-
buildStart() {
|
|
28
|
-
stylexRules = {};
|
|
29
|
-
},
|
|
30
|
-
generateBundle() {
|
|
31
|
-
const rules = Object.values(stylexRules).flat();
|
|
32
|
-
if (rules.length > 0) {
|
|
33
|
-
const collectedCSS = stylexBabelPlugin.processStylexRules(rules, useCSSLayers);
|
|
34
|
-
this.emitFile({
|
|
35
|
-
fileName,
|
|
36
|
-
source: collectedCSS,
|
|
37
|
-
type: 'asset'
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
shouldTransformCachedModule(_ref) {
|
|
42
|
-
let {
|
|
43
|
-
code: _code,
|
|
44
|
-
id,
|
|
45
|
-
meta
|
|
46
|
-
} = _ref;
|
|
47
|
-
stylexRules[id] = meta.stylex;
|
|
48
|
-
return false;
|
|
49
|
-
},
|
|
50
|
-
async transform(inputCode, id) {
|
|
51
|
-
if (!importSources.some(importName => typeof importName === 'string' ? inputCode.includes(importName) : inputCode.includes(importName.from))) {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
const result = await transformAsync(inputCode, {
|
|
55
|
-
babelrc: false,
|
|
56
|
-
filename: id,
|
|
57
|
-
presets,
|
|
58
|
-
plugins: [...plugins, /\.jsx?/.test(path.extname(id)) ? flowSyntaxPlugin : [typescriptSyntaxPlugin, {
|
|
59
|
-
isTSX: true
|
|
60
|
-
}], jsxSyntaxPlugin, stylexBabelPlugin.withOptions({
|
|
61
|
-
...options,
|
|
62
|
-
dev,
|
|
63
|
-
unstable_moduleResolution
|
|
64
|
-
})]
|
|
65
|
-
});
|
|
66
|
-
if (result == null) {
|
|
67
|
-
console.warn('stylex: transformAsync returned null');
|
|
68
|
-
return {
|
|
69
|
-
code: inputCode
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
const {
|
|
73
|
-
code,
|
|
74
|
-
map,
|
|
75
|
-
metadata
|
|
76
|
-
} = result;
|
|
77
|
-
if (code == null) {
|
|
78
|
-
console.warn('stylex: transformAsync returned null code');
|
|
79
|
-
return {
|
|
80
|
-
code: inputCode
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
if (!dev && metadata.stylex != null && metadata.stylex.length > 0) {
|
|
84
|
-
stylexRules[id] = metadata.stylex;
|
|
85
|
-
}
|
|
86
|
-
return {
|
|
87
|
-
code,
|
|
88
|
-
map: map,
|
|
89
|
-
meta: metadata
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
}
|
package/lib/index.js.flow
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
* @flow strict
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { type PluginItem } from '../flow_modules/@babel/core';
|
|
11
|
-
import type { Options } from '@stylexjs/babel-plugin';
|
|
12
|
-
import type { Plugin } from '../flow_modules/rollup';
|
|
13
|
-
|
|
14
|
-
export type PluginOptions = $ReadOnly<{
|
|
15
|
-
...Partial<Options>,
|
|
16
|
-
fileName?: string,
|
|
17
|
-
babelConfig?: $ReadOnly<{
|
|
18
|
-
plugins?: $ReadOnlyArray<PluginItem>,
|
|
19
|
-
presets?: $ReadOnlyArray<PluginItem>,
|
|
20
|
-
}>,
|
|
21
|
-
useCSSLayers?: boolean,
|
|
22
|
-
...
|
|
23
|
-
}>;
|
|
24
|
-
|
|
25
|
-
declare export default function stylexPlugin(PluginOptions): Plugin<>;
|