@compiled/parcel-transformer 0.10.0 → 0.11.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/dist/index.js +14 -6
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
- package/src/__tests__/transformer.parceltest.ts +65 -39
- package/src/index.ts +19 -7
package/dist/index.js
CHANGED
|
@@ -40,9 +40,11 @@ exports.default = new plugin_1.Transformer({
|
|
|
40
40
|
// Compiled should run before any other JS transformer.
|
|
41
41
|
return false;
|
|
42
42
|
},
|
|
43
|
-
async parse({ asset, config }) {
|
|
43
|
+
async parse({ asset, config, options }) {
|
|
44
44
|
var _a, _b;
|
|
45
|
-
|
|
45
|
+
// Disable stylesheet extraction locally due to https://github.com/atlassian-labs/compiled/issues/1306
|
|
46
|
+
const extract = config.extract && options.mode !== 'development';
|
|
47
|
+
if (!asset.isSource && !extract) {
|
|
46
48
|
// Only parse source (pre-built code should already have been baked) or if stylesheet extraction is enabled
|
|
47
49
|
return undefined;
|
|
48
50
|
}
|
|
@@ -67,7 +69,7 @@ exports.default = new plugin_1.Transformer({
|
|
|
67
69
|
program,
|
|
68
70
|
};
|
|
69
71
|
},
|
|
70
|
-
async transform({ asset, config }) {
|
|
72
|
+
async transform({ asset, config, options }) {
|
|
71
73
|
var _a, _b, _c;
|
|
72
74
|
const ast = await asset.getAST();
|
|
73
75
|
if (!ast) {
|
|
@@ -75,6 +77,8 @@ exports.default = new plugin_1.Transformer({
|
|
|
75
77
|
// Since this is undefined (or in node modules) we aren't interested in it.
|
|
76
78
|
return [asset];
|
|
77
79
|
}
|
|
80
|
+
// Disable stylesheet extraction locally due to https://github.com/atlassian-labs/compiled/issues/1306
|
|
81
|
+
const extract = config.extract && options.mode !== 'development';
|
|
78
82
|
const includedFiles = [];
|
|
79
83
|
const code = asset.isASTDirty() ? undefined : await asset.getCode();
|
|
80
84
|
const resolver = enhanced_resolve_1.ResolverFactory.createResolver(Object.assign(Object.assign(Object.assign({ fileSystem: new enhanced_resolve_1.CachedInputFileSystem(fs_1.default, 4000) }, (config.extensions && {
|
|
@@ -103,11 +107,10 @@ exports.default = new plugin_1.Transformer({
|
|
|
103
107
|
},
|
|
104
108
|
}, cache: false }),
|
|
105
109
|
],
|
|
106
|
-
|
|
110
|
+
extract && [
|
|
107
111
|
'@compiled/babel-plugin-strip-runtime',
|
|
108
112
|
{
|
|
109
|
-
|
|
110
|
-
compiledRequireExclude: config.ssr,
|
|
113
|
+
compiledRequireExclude: true,
|
|
111
114
|
},
|
|
112
115
|
],
|
|
113
116
|
].filter(utils_1.toBoolean),
|
|
@@ -123,6 +126,11 @@ exports.default = new plugin_1.Transformer({
|
|
|
123
126
|
asset.invalidateOnFileChange(file);
|
|
124
127
|
});
|
|
125
128
|
asset.setCode(output);
|
|
129
|
+
if (extract) {
|
|
130
|
+
// Store styleRules to asset.meta to be used by @compiled/parcel-optimizer
|
|
131
|
+
const metadata = result === null || result === void 0 ? void 0 : result.metadata;
|
|
132
|
+
asset.meta.styleRules = metadata.styleRules;
|
|
133
|
+
}
|
|
126
134
|
return [asset];
|
|
127
135
|
},
|
|
128
136
|
async generate({ asset, ast }) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,4CAAoB;AACpB,+BAAqC;AAErC,sCAAgE;AAChE,iEAAwC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,4CAAoB;AACpB,+BAAqC;AAErC,sCAAgE;AAChE,iEAAwC;AAMxC,2CAA4C;AAC5C,2CAA6C;AAC7C,oEAA2C;AAC3C,uDAA0E;AAI1E,MAAM,WAAW,GAAG;IAClB,gBAAgB;IAChB,qBAAqB;IACrB,gBAAgB;IAChB,uBAAuB;CACxB,CAAC;AAEF;;GAEG;AACH,kBAAe,IAAI,oBAAW,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AAC;YACvD,KAAK,CAAC,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC;SAC7C;QAED,OAAO,CAAC,KAAK,CAAC,CAAC;IACjB,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE;QAC3B,oFAAoF;QACpF,4EAA4E;QAC5E,uCAAuC;QACvC,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,IAAA,mBAAQ,EAAC,GAAG,CAAC,OAAO,EAAE;YACpD,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,UAAU,EAAE,IAAI;YAChB,cAAc,EAAE,KAAK,CAAC,QAAQ;SAC/B,CAAC,CAAC;QAEH,OAAO;YACL,OAAO,EAAE,IAAI;YACb,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,IAAI,oBAAS,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI;SAC3D,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@compiled/parcel-transformer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "A familiar and performant compile time CSS-in-JS library for React.",
|
|
5
5
|
"homepage": "https://compiledcssinjs.com/docs/pkg-parcel-transformer",
|
|
6
6
|
"bugs": "https://github.com/atlassian-labs/compiled/issues/new?assignees=&labels=bug&template=bug_report.md",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@babel/core": "^7.17.10",
|
|
24
24
|
"@babel/generator": "^7.17.10",
|
|
25
|
-
"@compiled/babel-plugin": "^0.
|
|
26
|
-
"@compiled/babel-plugin-strip-runtime": "^0.
|
|
25
|
+
"@compiled/babel-plugin": "^0.17.1",
|
|
26
|
+
"@compiled/babel-plugin-strip-runtime": "^0.17.0",
|
|
27
27
|
"@compiled/utils": "^0.6.16",
|
|
28
28
|
"@parcel/plugin": "^2.3.2",
|
|
29
29
|
"@parcel/source-map": "^2.0.2",
|
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
"@parcel/core": "^2.3.1",
|
|
34
34
|
"@parcel/fs": "^2.3.1",
|
|
35
35
|
"@parcel/types": "^2.3.1",
|
|
36
|
-
"@types/babel__core": "^7.1.19"
|
|
36
|
+
"@types/babel__core": "^7.1.19",
|
|
37
|
+
"prettier": "^2.7.1"
|
|
37
38
|
},
|
|
38
39
|
"engines": {
|
|
39
40
|
"parcel": "^2.0.0"
|
|
@@ -2,6 +2,7 @@ import { join } from 'path';
|
|
|
2
2
|
|
|
3
3
|
import Parcel, { createWorkerFarm } from '@parcel/core';
|
|
4
4
|
import { MemoryFS } from '@parcel/fs';
|
|
5
|
+
import { format } from 'prettier';
|
|
5
6
|
|
|
6
7
|
const rootPath = join(__dirname, '..', '..', '..', '..');
|
|
7
8
|
const fixtureRoot = join(rootPath, 'fixtures/parcel-transformer-test-app');
|
|
@@ -18,8 +19,9 @@ afterAll(() => {
|
|
|
18
19
|
workerFarm.end();
|
|
19
20
|
});
|
|
20
21
|
|
|
22
|
+
const outputFS = new MemoryFS(workerFarm);
|
|
23
|
+
|
|
21
24
|
const getParcelInstance = (workingDir: string) => {
|
|
22
|
-
const outputFS = new MemoryFS(workerFarm);
|
|
23
25
|
return new Parcel({
|
|
24
26
|
config: join(workingDir, '.parcelrc'),
|
|
25
27
|
entries: [join(workingDir, 'src', 'index.html')],
|
|
@@ -30,6 +32,7 @@ const getParcelInstance = (workingDir: string) => {
|
|
|
30
32
|
},
|
|
31
33
|
},
|
|
32
34
|
workerFarm,
|
|
35
|
+
mode: 'production',
|
|
33
36
|
});
|
|
34
37
|
};
|
|
35
38
|
|
|
@@ -87,7 +90,7 @@ it('transforms assets with custom resolver and statically evaluates imports', as
|
|
|
87
90
|
|
|
88
91
|
it('transforms assets with compiled and extraction babel plugins', async () => {
|
|
89
92
|
const parcel = getParcelInstance(extractionFixtureRoot);
|
|
90
|
-
const { changedAssets } = await parcel.run();
|
|
93
|
+
const { changedAssets, bundleGraph } = await parcel.run();
|
|
91
94
|
const assets = Array.from(changedAssets.values());
|
|
92
95
|
|
|
93
96
|
const indexJsCode = await assets
|
|
@@ -95,61 +98,84 @@ it('transforms assets with compiled and extraction babel plugins', async () => {
|
|
|
95
98
|
?.getCode();
|
|
96
99
|
expect(indexJsCode).toMatchInlineSnapshot(`
|
|
97
100
|
"var parcelHelpers = require(\\"@parcel/transformer-js/src/esmodule-helpers.js\\");
|
|
98
|
-
var
|
|
99
|
-
var _runtime = require(\\"@compiled/react/runtime\\");
|
|
101
|
+
var _jsxRuntime = require(\\"react/jsx-runtime\\");
|
|
102
|
+
/* index.jsx generated by @compiled/babel-plugin v0.0.0 */ var _runtime = require(\\"@compiled/react/runtime\\");
|
|
100
103
|
var _babelComponentFixture = require(\\"@compiled/babel-component-fixture\\");
|
|
101
104
|
var _babelComponentFixtureDefault = parcelHelpers.interopDefault(_babelComponentFixture);
|
|
102
|
-
var _this = undefined;
|
|
103
|
-
/* index.jsx generated by @compiled/babel-plugin v0.0.0 */ require(\\"compiled-css!?style=._syaz5scu%7Bcolor%3Ared%7D\\");
|
|
104
|
-
require(\\"compiled-css!?style=._1wyb12am%7Bfont-size%3A50px%7D\\");
|
|
105
105
|
var App = function() {
|
|
106
|
-
/*#__PURE__*/ return
|
|
106
|
+
/*#__PURE__*/ return _jsxRuntime.jsxs(_jsxRuntime.Fragment, {
|
|
107
107
|
children: [
|
|
108
|
-
/*#__PURE__*/
|
|
108
|
+
/*#__PURE__*/ _jsxRuntime.jsx(\\"div\\", {
|
|
109
109
|
className: _runtime.ax([
|
|
110
110
|
\\"_1wyb12am _syaz5scu\\"
|
|
111
111
|
]),
|
|
112
112
|
children: \\"CSS prop\\"
|
|
113
|
-
},
|
|
114
|
-
|
|
115
|
-
lineNumber: 11,
|
|
116
|
-
columnNumber: 5
|
|
117
|
-
}, _this),
|
|
118
|
-
/*#__PURE__*/ _jsxDevRuntime.jsxDEV(_babelComponentFixtureDefault.default, {
|
|
113
|
+
}),
|
|
114
|
+
/*#__PURE__*/ _jsxRuntime.jsx(_babelComponentFixtureDefault.default, {
|
|
119
115
|
children: \\"Babel component\\"
|
|
120
|
-
}
|
|
121
|
-
fileName: \\"src/index.jsx\\",
|
|
122
|
-
lineNumber: 12,
|
|
123
|
-
columnNumber: 5
|
|
124
|
-
}, _this)
|
|
116
|
+
})
|
|
125
117
|
]
|
|
126
|
-
}
|
|
118
|
+
});
|
|
127
119
|
};
|
|
128
120
|
"
|
|
129
121
|
`);
|
|
130
122
|
|
|
123
|
+
const htmlAsset = Array.from(changedAssets.values()).find(
|
|
124
|
+
(asset) => asset.filePath === join(extractionFixtureRoot, '/src/index.html')
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
const outputHtml = await outputFS.readFile(
|
|
128
|
+
bundleGraph.getBundlesWithAsset(htmlAsset!)[0].filePath,
|
|
129
|
+
'utf8'
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
const css = /<style>(.*?)<\/style>/.exec(outputHtml)?.pop();
|
|
133
|
+
|
|
134
|
+
if (!css) throw new Error('No CSS is found.');
|
|
135
|
+
|
|
136
|
+
expect(
|
|
137
|
+
format(css, {
|
|
138
|
+
parser: 'css',
|
|
139
|
+
singleQuote: true,
|
|
140
|
+
})
|
|
141
|
+
).toMatchInlineSnapshot(`
|
|
142
|
+
"._1wyb12am {
|
|
143
|
+
font-size: 50px;
|
|
144
|
+
}
|
|
145
|
+
._syaz5scu {
|
|
146
|
+
color: red;
|
|
147
|
+
}
|
|
148
|
+
._syaz13q2 {
|
|
149
|
+
color: blue;
|
|
150
|
+
}
|
|
151
|
+
._1wyb1ul9 {
|
|
152
|
+
font-size: 30px;
|
|
153
|
+
}
|
|
154
|
+
._19itlf8h {
|
|
155
|
+
border: 2px solid blue;
|
|
156
|
+
}
|
|
157
|
+
._ca0q1vi7 {
|
|
158
|
+
padding-top: 32px;
|
|
159
|
+
}
|
|
160
|
+
._u5f31vi7 {
|
|
161
|
+
padding-right: 32px;
|
|
162
|
+
}
|
|
163
|
+
._n3td1vi7 {
|
|
164
|
+
padding-bottom: 32px;
|
|
165
|
+
}
|
|
166
|
+
._19bv1vi7 {
|
|
167
|
+
padding-left: 32px;
|
|
168
|
+
}
|
|
169
|
+
._19pk1ul9 {
|
|
170
|
+
margin-top: 30px;
|
|
171
|
+
}
|
|
172
|
+
"
|
|
173
|
+
`);
|
|
174
|
+
|
|
131
175
|
const babelComponentCode = await assets
|
|
132
176
|
.find((asset) => asset.filePath === join(babelComponentFixture, 'dist/index.js'))
|
|
133
177
|
?.getCode();
|
|
134
178
|
|
|
135
|
-
const extractedCss = babelComponentCode
|
|
136
|
-
?.slice(0, babelComponentCode.indexOf('exports.default = BabelComponent;'))
|
|
137
|
-
.trim();
|
|
138
|
-
expect(extractedCss).toMatchInlineSnapshot(`
|
|
139
|
-
"/* index.jsx generated by @compiled/babel-plugin v0.0.0 */ \\"use strict\\";
|
|
140
|
-
require(\\"compiled-css!?style=._19pk1ul9%7Bmargin-top%3A30px%7D\\");
|
|
141
|
-
require(\\"compiled-css!?style=._19bv1vi7%7Bpadding-left%3A32px%7D\\");
|
|
142
|
-
require(\\"compiled-css!?style=._n3td1vi7%7Bpadding-bottom%3A32px%7D\\");
|
|
143
|
-
require(\\"compiled-css!?style=._u5f31vi7%7Bpadding-right%3A32px%7D\\");
|
|
144
|
-
require(\\"compiled-css!?style=._ca0q1vi7%7Bpadding-top%3A32px%7D\\");
|
|
145
|
-
require(\\"compiled-css!?style=._19itlf8h%7Bborder%3A2px%20solid%20blue%7D\\");
|
|
146
|
-
require(\\"compiled-css!?style=._1wyb1ul9%7Bfont-size%3A30px%7D\\");
|
|
147
|
-
require(\\"compiled-css!?style=._syaz13q2%7Bcolor%3Ablue%7D\\");
|
|
148
|
-
Object.defineProperty(exports, \\"__esModule\\", {
|
|
149
|
-
value: true
|
|
150
|
-
});"
|
|
151
|
-
`);
|
|
152
|
-
|
|
153
179
|
const extractedComponent = babelComponentCode
|
|
154
180
|
?.slice(babelComponentCode.indexOf('var Button'))
|
|
155
181
|
.trim();
|
package/src/index.ts
CHANGED
|
@@ -4,7 +4,10 @@ import { join, dirname } from 'path';
|
|
|
4
4
|
import { parseAsync, transformFromAstAsync } from '@babel/core';
|
|
5
5
|
import generate from '@babel/generator';
|
|
6
6
|
import type { PluginOptions as BabelPluginOptions } from '@compiled/babel-plugin';
|
|
7
|
-
import type {
|
|
7
|
+
import type {
|
|
8
|
+
PluginOptions as BabelStripRuntimePluginOptions,
|
|
9
|
+
BabelFileMetadata,
|
|
10
|
+
} from '@compiled/babel-plugin-strip-runtime';
|
|
8
11
|
import { toBoolean } from '@compiled/utils';
|
|
9
12
|
import { Transformer } from '@parcel/plugin';
|
|
10
13
|
import SourceMap from '@parcel/source-map';
|
|
@@ -47,8 +50,10 @@ export default new Transformer<ParcelTransformerOpts>({
|
|
|
47
50
|
return false;
|
|
48
51
|
},
|
|
49
52
|
|
|
50
|
-
async parse({ asset, config }) {
|
|
51
|
-
|
|
53
|
+
async parse({ asset, config, options }) {
|
|
54
|
+
// Disable stylesheet extraction locally due to https://github.com/atlassian-labs/compiled/issues/1306
|
|
55
|
+
const extract = config.extract && options.mode !== 'development';
|
|
56
|
+
if (!asset.isSource && !extract) {
|
|
52
57
|
// Only parse source (pre-built code should already have been baked) or if stylesheet extraction is enabled
|
|
53
58
|
return undefined;
|
|
54
59
|
}
|
|
@@ -77,7 +82,7 @@ export default new Transformer<ParcelTransformerOpts>({
|
|
|
77
82
|
};
|
|
78
83
|
},
|
|
79
84
|
|
|
80
|
-
async transform({ asset, config }) {
|
|
85
|
+
async transform({ asset, config, options }) {
|
|
81
86
|
const ast = await asset.getAST();
|
|
82
87
|
if (!ast) {
|
|
83
88
|
// We will only receive ASTs for assets we're interested in.
|
|
@@ -85,6 +90,8 @@ export default new Transformer<ParcelTransformerOpts>({
|
|
|
85
90
|
return [asset];
|
|
86
91
|
}
|
|
87
92
|
|
|
93
|
+
// Disable stylesheet extraction locally due to https://github.com/atlassian-labs/compiled/issues/1306
|
|
94
|
+
const extract = config.extract && options.mode !== 'development';
|
|
88
95
|
const includedFiles: string[] = [];
|
|
89
96
|
const code = asset.isASTDirty() ? undefined : await asset.getCode();
|
|
90
97
|
|
|
@@ -124,11 +131,10 @@ export default new Transformer<ParcelTransformerOpts>({
|
|
|
124
131
|
cache: false,
|
|
125
132
|
} as BabelPluginOptions,
|
|
126
133
|
],
|
|
127
|
-
|
|
134
|
+
extract && [
|
|
128
135
|
'@compiled/babel-plugin-strip-runtime',
|
|
129
136
|
{
|
|
130
|
-
|
|
131
|
-
compiledRequireExclude: config.ssr,
|
|
137
|
+
compiledRequireExclude: true,
|
|
132
138
|
} as BabelStripRuntimePluginOptions,
|
|
133
139
|
],
|
|
134
140
|
].filter(toBoolean),
|
|
@@ -148,6 +154,12 @@ export default new Transformer<ParcelTransformerOpts>({
|
|
|
148
154
|
|
|
149
155
|
asset.setCode(output);
|
|
150
156
|
|
|
157
|
+
if (extract) {
|
|
158
|
+
// Store styleRules to asset.meta to be used by @compiled/parcel-optimizer
|
|
159
|
+
const metadata = result?.metadata as BabelFileMetadata;
|
|
160
|
+
asset.meta.styleRules = metadata.styleRules;
|
|
161
|
+
}
|
|
162
|
+
|
|
151
163
|
return [asset];
|
|
152
164
|
},
|
|
153
165
|
|