@compiled/webpack-loader 0.14.0 → 0.15.0
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/__fixtures__/lib/other-css.d.ts +1 -0
- package/dist/__fixtures__/lib/other-css.js +7 -0
- package/dist/__fixtures__/lib/other-css.js.map +1 -0
- package/dist/__fixtures__/non-compiled-import-source.d.ts +2 -0
- package/dist/__fixtures__/non-compiled-import-source.js +10 -0
- package/dist/__fixtures__/non-compiled-import-source.js.map +1 -0
- package/dist/compiled-loader.js +5 -4
- package/dist/compiled-loader.js.map +1 -1
- package/dist/create-default-resolver.js +4 -1
- package/dist/create-default-resolver.js.map +1 -1
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +8 -2
- package/dist/utils.js.map +1 -1
- package/package.json +2 -2
- package/src/__fixtures__/lib/other-css.ts +1 -0
- package/src/__fixtures__/non-compiled-import-source.tsx +6 -0
- package/src/__tests__/compiled-loader.test.ts +34 -1
- package/src/__tests__/test-utils.ts +4 -0
- package/src/compiled-loader.ts +5 -4
- package/src/create-default-resolver.ts +5 -1
- package/src/utils.ts +16 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { css, jsx } from '@compiled/react';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.jsx = exports.css = void 0;
|
|
4
|
+
var react_1 = require("@compiled/react");
|
|
5
|
+
Object.defineProperty(exports, "css", { enumerable: true, get: function () { return react_1.css; } });
|
|
6
|
+
Object.defineProperty(exports, "jsx", { enumerable: true, get: function () { return react_1.jsx; } });
|
|
7
|
+
//# sourceMappingURL=other-css.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"other-css.js","sourceRoot":"","sources":["../../../src/__fixtures__/lib/other-css.ts"],"names":[],"mappings":";;;AAAA,yCAA2C;AAAlC,4FAAA,GAAG,OAAA;AAAE,4FAAA,GAAG,OAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.App = void 0;
|
|
4
|
+
/** @jsx jsx */
|
|
5
|
+
// @ts-expect-error -- fake package
|
|
6
|
+
const css_1 = require("@other/css");
|
|
7
|
+
// @ts-expect-error -- fake package
|
|
8
|
+
const App = () => (0, css_1.jsx)("div", { css: { margin: 0 } });
|
|
9
|
+
exports.App = App;
|
|
10
|
+
//# sourceMappingURL=non-compiled-import-source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"non-compiled-import-source.js","sourceRoot":"","sources":["../../src/__fixtures__/non-compiled-import-source.tsx"],"names":[],"mappings":";;;AAAA,eAAe;AACf,mCAAmC;AACnC,oCAAiC;AAEjC,mCAAmC;AAC5B,MAAM,GAAG,GAAG,GAAgB,EAAE,CAAC,wBAAK,GAAG,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,GAAI,CAAC;AAArD,QAAA,GAAG,OAAkD"}
|
package/dist/compiled-loader.js
CHANGED
|
@@ -111,14 +111,15 @@ function getLoaderOptions(context) {
|
|
|
111
111
|
async function compiledLoader(code) {
|
|
112
112
|
var _a, _b, _c, _d;
|
|
113
113
|
const callback = this.async();
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
114
|
+
const _e = getLoaderOptions(this), { resolve } = _e, options = __rest(_e, ["resolve"]);
|
|
115
|
+
const importSources = ['@compiled/react', ...(options.importSources || [])];
|
|
116
|
+
// Bail early if we're looking at Compiled runtime code or Compiled (via an importSource) isn't in the module
|
|
117
|
+
if (this.resourcePath.includes('/node_modules/@compiled/react') ||
|
|
118
|
+
!importSources.some((name) => code.includes(name))) {
|
|
117
119
|
return callback(null, code);
|
|
118
120
|
}
|
|
119
121
|
try {
|
|
120
122
|
const includedFiles = [];
|
|
121
|
-
const _e = getLoaderOptions(this), { resolve } = _e, options = __rest(_e, ["resolve"]);
|
|
122
123
|
// Transform to an AST using the local babel config.
|
|
123
124
|
const ast = await (0, core_1.parseAsync)(code, {
|
|
124
125
|
filename: this.resourcePath,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compiled-loader.js","sourceRoot":"","sources":["../src/compiled-loader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,+BAAiC;AAEjC,sCAAgE;AAChE,2CAAuF;AACvF,+CAA0C;AAG1C,uEAAkE;AAClE,qDAA8D;AAG9D,IAAI,UAAU,GAAG,KAAK,CAAC;AAEvB;;;;;GAKG;AACH,SAAS,gBAAgB,CAAC,OAA6C;IACrE,MAAM,EACJ,IAAI,GAAG,IAAI,EACX,OAAO,GAAG,KAAK,EACf,WAAW,GAAG,SAAS,EACvB,KAAK,GAAG,SAAS,EACjB,OAAO,GAAG,EAAE,EACZ,UAAU,GAAG,SAAS,EACtB,kBAAkB,GAAG,oCAA4B,EACjD,uBAAuB,GAAG,EAAE,EAC5B,CAAC,2BAAU,CAAC,EAAE,eAAe,GAAG,KAAK,EACrC,GAAG,GAAG,KAAK,EACX,WAAW,GAAG,IAAI,EAClB,gBAAgB,GAAG,KAAK,EACxB,uBAAuB,GAAG,SAAS,EACnC,wBAAwB,GAAG,SAAS,EACpC,QAAQ,GAAG,SAAS,EACpB,aAAa,GAAG,SAAS,GAC1B,GAA0B,OAAO,OAAO,CAAC,UAAU,KAAK,WAAW;QAClE,CAAC,CAAC,kBAAkB;YAClB,IAAA,yBAAU,EAAC,OAAO,CAAC;QACrB,CAAC,CAAC,kBAAkB;YAClB,OAAO,CAAC,UAAU,CAAC;gBACjB,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,IAAI,EAAE;wBACJ,IAAI,EAAE,SAAS;qBAChB;oBACD,OAAO,EAAE;wBACP,IAAI,EAAE,SAAS;qBAChB;oBACD,WAAW,EAAE;wBACX,IAAI,EAAE,SAAS;qBAChB;oBACD,KAAK,EAAE;wBACL,IAAI,EAAE,QAAQ;qBACf;oBACD,OAAO,EAAE;wBACP,IAAI,EAAE,QAAQ;qBACf;oBACD,UAAU,EAAE;wBACV,IAAI,EAAE,OAAO;qBACd;oBACD,kBAAkB,EAAE;wBAClB,IAAI,EAAE,OAAO;qBACd;oBACD,uBAAuB,EAAE;wBACvB,IAAI,EAAE,OAAO;qBACd;oBACD,CAAC,2BAAU,CAAC,EAAE;wBACZ,IAAI,EAAE,SAAS;qBAChB;oBACD,GAAG,EAAE;wBACH,IAAI,EAAE,SAAS;qBAChB;oBACD,WAAW,EAAE;wBACX,IAAI,EAAE,SAAS;qBAChB;oBACD,gBAAgB,EAAE;wBAChB,IAAI,EAAE,SAAS;qBAChB;oBACD,uBAAuB,EAAE;wBACvB,IAAI,EAAE,QAAQ;qBACf;oBACD,wBAAwB,EAAE;wBACxB,IAAI,EAAE,QAAQ;qBACf;oBACD,QAAQ,EAAE;wBACR,IAAI,EAAE,QAAQ;qBACf;oBACD,aAAa,EAAE;wBACb,IAAI,EAAE,OAAO;qBACd;iBACF;aACF,CAAC,CAAC;IAEP,OAAO;QACL,IAAI;QACJ,OAAO;QACP,WAAW;QACX,KAAK;QACL,OAAO;QACP,UAAU;QACV,kBAAkB;QAClB,uBAAuB;QACvB,CAAC,2BAAU,CAAC,EAAE,eAAe;QAC7B,GAAG;QACH,WAAW;QACX,gBAAgB;QAChB,uBAAuB;QACvB,wBAAwB;QACxB,QAAQ;QACR,aAAa;KACd,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACY,KAAK,UAAU,cAAc,CAE1C,IAAY;;IAEZ,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"compiled-loader.js","sourceRoot":"","sources":["../src/compiled-loader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,+BAAiC;AAEjC,sCAAgE;AAChE,2CAAuF;AACvF,+CAA0C;AAG1C,uEAAkE;AAClE,qDAA8D;AAG9D,IAA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,IAAA,+CAAqB,EAAC;gCACpB,cAAc,EAAE,OAAO;gCACvB,qBAAqB,EAAE,MAAA,IAAI,CAAC,YAAY,0CAAE,OAAO,CAAC,OAAO;6BAC1D,CAAC;iBAET;aACF,CAAC,MAAM,CAAC,iBAAS,CAAC;SACpB,CAAC,CAAC;QAEH,aAAa,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YAC7B,IAAI,CAAC,aAAa,CAAC,IAAA,gBAAS,EAAC,IAAI,CAAC,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;QAEH,QAAQ,CAAC,IAAI,EAAE,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,KAAI,EAAE,EAAE,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,GAAG,mCAAI,SAAS,CAAC,CAAC;KAC9D;IAAC,OAAO,CAAU,EAAE;QACnB,+CAA+C;QAC/C,MAAM,KAAK,GAAG,IAAA,mBAAW,EAAC,iBAAiB,EAAE,qBAAqB,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAC7E,QAAQ,CAAC,KAAK,CAAC,CAAC;KACjB;AACH,CAAC;AA/ED,iCA+EC;AAED,SAAgB,KAAK;IACnB,MAAM,OAAO,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACvC,IAAI,CAAC,UAAU,IAAI,OAAO,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,2BAAU,CAAC,EAAE;QAC1D,IAAI,CAAC,SAAS,CACZ,IAAA,mBAAW,EAAC,gBAAgB,CAAC,CAC3B,gLAAgL,CACjL,CACF,CAAC;QAEF,4FAA4F;QAC5F,UAAU,GAAG,IAAI,CAAC;KACnB;AACH,CAAC;AAZD,sBAYC"}
|
|
@@ -11,8 +11,11 @@ function createDefaultResolver({ resolveOptions, webpackResolveOptions }) {
|
|
|
11
11
|
// Setup the default resolver, where webpack will merge any passed in options with the default
|
|
12
12
|
// resolve configuration. Ideally, we use this.getResolve({ ...resolve, useSyncFileSystemCalls: true, })
|
|
13
13
|
// However, it does not work correctly when in development mode :/
|
|
14
|
+
// @ts-expect-error - enhanced-resolve CachedInputFileSystem types are not
|
|
15
|
+
// compatible with @types/node fs types
|
|
14
16
|
const resolver = enhanced_resolve_1.ResolverFactory.createResolver(Object.assign(Object.assign(Object.assign({
|
|
15
|
-
// @ts-expect-error
|
|
17
|
+
// @ts-expect-error - enhanced-resolve CachedInputFileSystem types are not
|
|
18
|
+
// compatible with @types/node fs types
|
|
16
19
|
fileSystem: new enhanced_resolve_1.CachedInputFileSystem(fs_1.default, 4000) }, (webpackResolveOptions !== null && webpackResolveOptions !== void 0 ? webpackResolveOptions : {})), resolveOptions), {
|
|
17
20
|
// This makes the resolver invoke the callback synchronously
|
|
18
21
|
useSyncFileSystemCalls: true }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-default-resolver.js","sourceRoot":"","sources":["../src/create-default-resolver.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,+BAA+B;AAG/B,uDAA0E;AAQ1E,SAAgB,qBAAqB,CAAC,EAAE,cAAc,EAAE,qBAAqB,EAAU;IACrF,8FAA8F;IAC9F,wGAAwG;IACxG,kEAAkE;
|
|
1
|
+
{"version":3,"file":"create-default-resolver.js","sourceRoot":"","sources":["../src/create-default-resolver.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,+BAA+B;AAG/B,uDAA0E;AAQ1E,SAAgB,qBAAqB,CAAC,EAAE,cAAc,EAAE,qBAAqB,EAAU;IACrF,8FAA8F;IAC9F,wGAAwG;IACxG,kEAAkE;IAElE,0EAA0E;IAC1E,uCAAuC;IACvC,MAAM,QAAQ,GAAG,kCAAe,CAAC,cAAc;QAC7C,0EAA0E;QAC1E,uCAAuC;QACvC,UAAU,EAAE,IAAI,wCAAqB,CAAC,YAAE,EAAE,IAAI,CAAC,IAC5C,CAAC,qBAAqB,aAArB,qBAAqB,cAArB,qBAAqB,GAAI,EAAE,CAAC,GAC7B,cAAc;QACjB,4DAA4D;QAC5D,sBAAsB,EAAE,IAAI,IAC5B,CAAC;IAEH,OAAO;QACL,6EAA6E;QAC7E,WAAW,EAAE,CAAC,OAAe,EAAE,OAAe,EAAE,EAAE;YAChD,OAAO,QAAQ,CAAC,WAAW,CAAC,EAAE,EAAE,IAAA,cAAO,EAAC,OAAO,CAAC,EAAE,OAAO,CAAW,CAAC;QACvE,CAAC;KACF,CAAC;AACJ,CAAC;AAvBD,sDAuBC"}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Compilation as CompilationType, Compiler, sources,
|
|
1
|
+
import type { Compilation as CompilationType, Compiler, sources, WebpackOptionsNormalized } from 'webpack';
|
|
2
2
|
/**
|
|
3
3
|
* Sets an option on the plugin config to tell loaders that the plugin has been configured.
|
|
4
4
|
* Bundling will throw if this option is missing (i.e. consumers did not setup correctly).
|
|
@@ -7,7 +7,7 @@ import type { Compilation as CompilationType, Compiler, sources, RuleSetRule } f
|
|
|
7
7
|
* @param pluginName
|
|
8
8
|
* @returns
|
|
9
9
|
*/
|
|
10
|
-
export declare const setPluginConfiguredOption: (rules:
|
|
10
|
+
export declare const setPluginConfiguredOption: (rules: WebpackOptionsNormalized['module']['rules'], pluginName: string) => void;
|
|
11
11
|
/**
|
|
12
12
|
* Returns the string representation of an assets source.
|
|
13
13
|
*
|
package/dist/utils.js
CHANGED
|
@@ -13,7 +13,8 @@ const setOptionOnCompiledWebpackLoader = (use, pluginName) => {
|
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
15
|
for (const nestedUse of use) {
|
|
16
|
-
if (
|
|
16
|
+
if (nestedUse &&
|
|
17
|
+
typeof nestedUse === 'object' &&
|
|
17
18
|
(nestedUse.loader === '@compiled/webpack-loader' ||
|
|
18
19
|
((_a = nestedUse.loader) === null || _a === void 0 ? void 0 : _a.includes('/node_modules/@compiled/webpack-loader')))) {
|
|
19
20
|
const { options } = nestedUse;
|
|
@@ -34,11 +35,16 @@ const setOptionOnCompiledWebpackLoader = (use, pluginName) => {
|
|
|
34
35
|
const setPluginConfiguredOption = (rules, pluginName) => {
|
|
35
36
|
var _a;
|
|
36
37
|
for (const r of rules) {
|
|
38
|
+
if (!r) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
37
41
|
const rule = r;
|
|
38
42
|
const nestedRules = (_a = rule.oneOf) !== null && _a !== void 0 ? _a : rule.rules;
|
|
39
43
|
if (nestedRules) {
|
|
40
44
|
for (const nestedRule of nestedRules) {
|
|
41
|
-
|
|
45
|
+
if (nestedRule) {
|
|
46
|
+
setOptionOnCompiledWebpackLoader(nestedRule.use, pluginName);
|
|
47
|
+
}
|
|
42
48
|
}
|
|
43
49
|
}
|
|
44
50
|
else {
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAQA;;;;;GAKG;AACH,MAAM,gCAAgC,GAAG,CAAC,GAAuB,EAAE,UAAkB,EAAE,EAAE;;IACvF,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE;QAC9C,OAAO;KACR;IAED,KAAK,MAAM,SAAS,IAAI,GAAG,EAAE;QAC3B,IACE,SAAS;YACT,OAAO,SAAS,KAAK,QAAQ;YAC7B,CAAC,SAAS,CAAC,MAAM,KAAK,0BAA0B;iBAC9C,MAAA,SAAS,CAAC,MAAM,0CAAE,QAAQ,CAAC,wCAAwC,CAAC,CAAA,CAAC,EACvE;YACA,MAAM,EAAE,OAAO,EAAE,GAAG,SAAS,CAAC;YAC9B,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO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CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAC5C,MAAM,cAAc;IAClB,iBAAiB;IACjB,WAAW,CAAC,KAAK,CAAC,aAAa;QAC/B,iBAAiB;QACjB,WAAW,CAAC,KAAK,CAAC,cAAc,CAAC;IAEnC,OAAO;QACL,GAAG,EAAE,CAAC,UAAkB,EAAE,QAAqD,EAAE,EAAE;YACjF,cAAc,CAAC,GAAG,CAChB,UAAU;gBACR,CAAC,CAAC,UAAU;gBACZ,CAAC,CAAC;oBACE,IAAI,EAAE,UAAU;oBAChB,KAAK,EAAE,WAAW,CAAC,kCAAkC;iBACtD,EACL,QAAQ,CACT,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AA7BW,QAAA,qBAAqB,yBA6BhC;AAEF;;;GAGG;AACI,MAAM,UAAU,GAAG,CAAC,QAAkB,EAAkB,EAAE;IAC/D,MAAM,EAAE,OAAO,EAAE;IACf,iBAAiB;IACjB,QAAQ,CAAC,OAAO;QAChB,iBAAiB;QACjB,EAAE,CAAC;IAEL,OAAO;IACL,iBAAiB;IACjB,OAAO;QACP,iBAAiB;QACjB,OAAO,CAAC,iBAAiB,CAAC,CAC3B,CAAC;AACJ,CAAC,CAAC;AAbW,QAAA,UAAU,cAarB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@compiled/webpack-loader",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "A familiar and performant compile time CSS-in-JS library for React.",
|
|
5
5
|
"homepage": "https://compiledcssinjs.com/docs/pkg-webpack-loader",
|
|
6
6
|
"bugs": "https://github.com/atlassian-labs/compiled/issues/new?assignees=&labels=bug&template=bug_report.md",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@babel/core": "^7.21.8",
|
|
24
24
|
"@babel/parser": "^7.21.8",
|
|
25
|
-
"@compiled/babel-plugin": "^0.
|
|
25
|
+
"@compiled/babel-plugin": "^0.30.0",
|
|
26
26
|
"@compiled/babel-plugin-strip-runtime": "^0.29.0",
|
|
27
27
|
"@compiled/css": "^0.14.0",
|
|
28
28
|
"@compiled/utils": "^0.11.2",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { css, jsx } from '@compiled/react';
|
|
@@ -20,7 +20,7 @@ describe.each<'development' | 'production'>(['development', 'production'])(
|
|
|
20
20
|
mode,
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
-
it('does not transform files that do not contain
|
|
23
|
+
it('does not transform files that do not contain styles', async () => {
|
|
24
24
|
const assets = await bundle(join(fixturesPath, 'no-compiled-styles.ts'));
|
|
25
25
|
|
|
26
26
|
if (mode === 'development') {
|
|
@@ -30,6 +30,39 @@ describe.each<'development' | 'production'>(['development', 'production'])(
|
|
|
30
30
|
}
|
|
31
31
|
});
|
|
32
32
|
|
|
33
|
+
it('does not transform files that do not contain @compiled/react', async () => {
|
|
34
|
+
const assets = await bundle(join(fixturesPath, 'non-compiled-import-source.tsx'));
|
|
35
|
+
|
|
36
|
+
if (mode === 'development') {
|
|
37
|
+
// This appears to just default to eval mode—I can't test much about it…
|
|
38
|
+
expect(assets['main.js']).toInclude('eval()');
|
|
39
|
+
expect(assets['main.js']).toInclude('React.createElement');
|
|
40
|
+
expect(assets['main.js']).not.toMatch(/\{[\s]*margin(-[a-z]+)?:[\s]*0[\s]*\}/);
|
|
41
|
+
expect(assets['main.js']).toInclude(
|
|
42
|
+
'__webpack_require__("./packages/webpack-loader/src/__fixtures__/non-compiled-import-source.tsx");'
|
|
43
|
+
);
|
|
44
|
+
} else {
|
|
45
|
+
expect(assets['main.js']).toMatch(
|
|
46
|
+
/@compiled\/react[\\n\s]+Code was executed when it shouldn't have\./
|
|
47
|
+
);
|
|
48
|
+
expect(assets['main.js']).toInclude('{margin:0}');
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('transforms a file that does not contain @compiled/react, but contains an importSource', async () => {
|
|
53
|
+
const assets = await bundle(join(fixturesPath, 'non-compiled-import-source.tsx'), {
|
|
54
|
+
importSources: ['@other/css'],
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
expect(assets['main.js']).not.toInclude('{margin:0}');
|
|
58
|
+
expect(assets['main.js']).toIncludeMultiple([
|
|
59
|
+
'._19pkidpf{margin-top:0}',
|
|
60
|
+
'._2hwxidpf{margin-right:0}',
|
|
61
|
+
'._otyridpf{margin-bottom:0}',
|
|
62
|
+
'._18u0idpf{margin-left:0}',
|
|
63
|
+
]);
|
|
64
|
+
});
|
|
65
|
+
|
|
33
66
|
it('transforms local styles', async () => {
|
|
34
67
|
const assets = await bundle(join(fixturesPath, 'local-styles.tsx'));
|
|
35
68
|
|
|
@@ -17,6 +17,7 @@ export interface BundleOptions {
|
|
|
17
17
|
mode: 'development' | 'production';
|
|
18
18
|
resolve?: ResolveOptions;
|
|
19
19
|
resolver?: string;
|
|
20
|
+
importSources?: string[];
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
export function bundle(
|
|
@@ -29,6 +30,7 @@ export function bundle(
|
|
|
29
30
|
mode,
|
|
30
31
|
resolve = {},
|
|
31
32
|
resolver,
|
|
33
|
+
importSources,
|
|
32
34
|
}: BundleOptions
|
|
33
35
|
): Promise<Record<string, string>> {
|
|
34
36
|
const outputPath = join(__dirname, 'dist');
|
|
@@ -56,6 +58,7 @@ export function bundle(
|
|
|
56
58
|
options: {
|
|
57
59
|
extract,
|
|
58
60
|
importReact: false,
|
|
61
|
+
importSources,
|
|
59
62
|
optimizeCss: false,
|
|
60
63
|
resolve,
|
|
61
64
|
resolver,
|
|
@@ -86,6 +89,7 @@ export function bundle(
|
|
|
86
89
|
resolve: {
|
|
87
90
|
alias: {
|
|
88
91
|
'webpack-alias': join(__dirname, '..', '__fixtures__', 'lib', 'webpack-alias.ts'),
|
|
92
|
+
'@other/css': join(__dirname, '..', '__fixtures__', 'lib', 'other-css.ts'),
|
|
89
93
|
},
|
|
90
94
|
extensions: ['.tsx', '.ts', '.jsx', '.js'],
|
|
91
95
|
},
|
package/src/compiled-loader.ts
CHANGED
|
@@ -124,18 +124,19 @@ export default async function compiledLoader(
|
|
|
124
124
|
code: string
|
|
125
125
|
): Promise<void> {
|
|
126
126
|
const callback = this.async();
|
|
127
|
+
const { resolve, ...options } = getLoaderOptions(this);
|
|
128
|
+
const importSources = ['@compiled/react', ...(options.importSources || [])];
|
|
127
129
|
|
|
128
|
-
// Bail early if
|
|
130
|
+
// Bail early if we're looking at Compiled runtime code or Compiled (via an importSource) isn't in the module
|
|
129
131
|
if (
|
|
130
|
-
|
|
131
|
-
|
|
132
|
+
this.resourcePath.includes('/node_modules/@compiled/react') ||
|
|
133
|
+
!importSources.some((name) => code.includes(name))
|
|
132
134
|
) {
|
|
133
135
|
return callback(null, code);
|
|
134
136
|
}
|
|
135
137
|
|
|
136
138
|
try {
|
|
137
139
|
const includedFiles: string[] = [];
|
|
138
|
-
const { resolve, ...options } = getLoaderOptions(this);
|
|
139
140
|
|
|
140
141
|
// Transform to an AST using the local babel config.
|
|
141
142
|
const ast = await parseAsync(code, {
|
|
@@ -14,8 +14,12 @@ export function createDefaultResolver({ resolveOptions, webpackResolveOptions }:
|
|
|
14
14
|
// Setup the default resolver, where webpack will merge any passed in options with the default
|
|
15
15
|
// resolve configuration. Ideally, we use this.getResolve({ ...resolve, useSyncFileSystemCalls: true, })
|
|
16
16
|
// However, it does not work correctly when in development mode :/
|
|
17
|
+
|
|
18
|
+
// @ts-expect-error - enhanced-resolve CachedInputFileSystem types are not
|
|
19
|
+
// compatible with @types/node fs types
|
|
17
20
|
const resolver = ResolverFactory.createResolver({
|
|
18
|
-
// @ts-expect-error
|
|
21
|
+
// @ts-expect-error - enhanced-resolve CachedInputFileSystem types are not
|
|
22
|
+
// compatible with @types/node fs types
|
|
19
23
|
fileSystem: new CachedInputFileSystem(fs, 4000),
|
|
20
24
|
...(webpackResolveOptions ?? {}),
|
|
21
25
|
...resolveOptions,
|
package/src/utils.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
Compilation as CompilationType,
|
|
3
|
+
Compiler,
|
|
4
|
+
sources,
|
|
5
|
+
RuleSetRule,
|
|
6
|
+
WebpackOptionsNormalized,
|
|
7
|
+
} from 'webpack';
|
|
2
8
|
|
|
3
9
|
/**
|
|
4
10
|
* Helper function to set plugin configured option on the @compiled/webpack-loader
|
|
@@ -13,6 +19,7 @@ const setOptionOnCompiledWebpackLoader = (use: RuleSetRule['use'], pluginName: s
|
|
|
13
19
|
|
|
14
20
|
for (const nestedUse of use) {
|
|
15
21
|
if (
|
|
22
|
+
nestedUse &&
|
|
16
23
|
typeof nestedUse === 'object' &&
|
|
17
24
|
(nestedUse.loader === '@compiled/webpack-loader' ||
|
|
18
25
|
nestedUse.loader?.includes('/node_modules/@compiled/webpack-loader'))
|
|
@@ -34,15 +41,21 @@ const setOptionOnCompiledWebpackLoader = (use: RuleSetRule['use'], pluginName: s
|
|
|
34
41
|
* @returns
|
|
35
42
|
*/
|
|
36
43
|
export const setPluginConfiguredOption = (
|
|
37
|
-
rules:
|
|
44
|
+
rules: WebpackOptionsNormalized['module']['rules'],
|
|
38
45
|
pluginName: string
|
|
39
46
|
): void => {
|
|
40
47
|
for (const r of rules) {
|
|
48
|
+
if (!r) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
|
|
41
52
|
const rule = r as RuleSetRule;
|
|
42
53
|
const nestedRules = rule.oneOf ?? rule.rules;
|
|
43
54
|
if (nestedRules) {
|
|
44
55
|
for (const nestedRule of nestedRules) {
|
|
45
|
-
|
|
56
|
+
if (nestedRule) {
|
|
57
|
+
setOptionOnCompiledWebpackLoader(nestedRule.use, pluginName);
|
|
58
|
+
}
|
|
46
59
|
}
|
|
47
60
|
} else {
|
|
48
61
|
setOptionOnCompiledWebpackLoader(rule.use, pluginName);
|