@compiled/webpack-loader 0.6.17 → 0.7.3

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.
Files changed (114) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/dist/{__tests__/fixtures/async.d.ts → __fixtures__/async-styles.d.ts} +0 -0
  3. package/dist/{__tests__/fixtures/async.js → __fixtures__/async-styles.js} +2 -2
  4. package/dist/__fixtures__/async-styles.js.map +1 -0
  5. package/dist/__fixtures__/babel.d.ts +2 -0
  6. package/dist/__fixtures__/babel.js +14 -0
  7. package/dist/__fixtures__/babel.js.map +1 -0
  8. package/dist/{__tests__/fixtures → __fixtures__}/binding-not-found.d.ts +1 -1
  9. package/dist/{__tests__/fixtures → __fixtures__}/binding-not-found.js +6 -9
  10. package/dist/__fixtures__/binding-not-found.js.map +1 -0
  11. package/dist/__fixtures__/common/colors.d.ts +7 -0
  12. package/dist/{__tests__/fixtures/imports → __fixtures__/common}/colors.js +5 -4
  13. package/dist/__fixtures__/common/colors.js.map +1 -0
  14. package/dist/__fixtures__/common/css-prop.d.ts +2 -0
  15. package/dist/__fixtures__/common/css-prop.js +9 -0
  16. package/dist/__fixtures__/common/css-prop.js.map +1 -0
  17. package/dist/__fixtures__/compiled-error.d.ts +2 -0
  18. package/dist/__fixtures__/compiled-error.js +10 -0
  19. package/dist/__fixtures__/compiled-error.js.map +1 -0
  20. package/dist/__fixtures__/important-styles.d.ts +3 -0
  21. package/dist/__fixtures__/important-styles.js +7 -0
  22. package/dist/__fixtures__/important-styles.js.map +1 -0
  23. package/dist/__fixtures__/lib/loader-alias.d.ts +1 -0
  24. package/dist/__fixtures__/lib/loader-alias.js +8 -0
  25. package/dist/__fixtures__/lib/loader-alias.js.map +1 -0
  26. package/dist/__fixtures__/lib/webpack-alias.d.ts +1 -0
  27. package/dist/__fixtures__/lib/webpack-alias.js +8 -0
  28. package/dist/__fixtures__/lib/webpack-alias.js.map +1 -0
  29. package/dist/__fixtures__/loader-alias.d.ts +2 -0
  30. package/dist/__fixtures__/loader-alias.js +12 -0
  31. package/dist/__fixtures__/loader-alias.js.map +1 -0
  32. package/dist/__fixtures__/local-styles.d.ts +2 -0
  33. package/dist/__fixtures__/local-styles.js +14 -0
  34. package/dist/__fixtures__/local-styles.js.map +1 -0
  35. package/dist/__fixtures__/no-compiled-styles.d.ts +0 -0
  36. package/dist/__fixtures__/no-compiled-styles.js +3 -0
  37. package/dist/__fixtures__/no-compiled-styles.js.map +1 -0
  38. package/dist/__fixtures__/relative-styles.d.ts +3 -0
  39. package/dist/__fixtures__/relative-styles.js +34 -0
  40. package/dist/__fixtures__/relative-styles.js.map +1 -0
  41. package/dist/__fixtures__/webpack-alias.d.ts +2 -0
  42. package/dist/__fixtures__/webpack-alias.js +12 -0
  43. package/dist/__fixtures__/webpack-alias.js.map +1 -0
  44. package/dist/compiled-loader.d.ts +4 -3
  45. package/dist/compiled-loader.js +53 -17
  46. package/dist/compiled-loader.js.map +1 -1
  47. package/dist/css-loader.d.ts +3 -3
  48. package/dist/css-loader.js +4 -1
  49. package/dist/css-loader.js.map +1 -1
  50. package/dist/extract-plugin.js +5 -5
  51. package/dist/extract-plugin.js.map +1 -1
  52. package/dist/index.d.ts +1 -0
  53. package/dist/types.d.ts +4 -58
  54. package/dist/{utils/webpack.d.ts → utils.d.ts} +1 -1
  55. package/dist/{utils/webpack.js → utils.js} +1 -1
  56. package/dist/utils.js.map +1 -0
  57. package/package.json +10 -9
  58. package/src/__fixtures__/async-styles.ts +1 -0
  59. package/src/__fixtures__/babel.tsx +11 -0
  60. package/src/{__tests__/fixtures → __fixtures__}/binding-not-found.tsx +2 -1
  61. package/src/{__tests__/fixtures/imports/colors.js → __fixtures__/common/colors.ts} +4 -3
  62. package/src/__fixtures__/common/css-prop.tsx +8 -0
  63. package/src/__fixtures__/compiled-error.tsx +7 -0
  64. package/src/__fixtures__/important-styles.tsx +6 -0
  65. package/src/__fixtures__/lib/babel-cjs.d.ts +3 -0
  66. package/src/{__tests__/fixtures/node_modules → __fixtures__/lib}/babel-cjs.js +0 -0
  67. package/src/__fixtures__/lib/babel-esm.d.ts +3 -0
  68. package/src/{__tests__/fixtures/node_modules → __fixtures__/lib}/babel-esm.js +0 -0
  69. package/src/__fixtures__/lib/loader-alias.ts +5 -0
  70. package/src/__fixtures__/lib/webpack-alias.ts +5 -0
  71. package/src/__fixtures__/loader-alias.tsx +8 -0
  72. package/src/__fixtures__/local-styles.tsx +14 -0
  73. package/src/__fixtures__/no-compiled-styles.ts +1 -0
  74. package/src/__fixtures__/relative-styles.tsx +39 -0
  75. package/src/__fixtures__/webpack-alias.tsx +8 -0
  76. package/src/__tests__/compiled-loader.test.tsx +70 -39
  77. package/src/__tests__/extract-plugin.test.tsx +82 -48
  78. package/src/__tests__/test-utils.tsx +103 -0
  79. package/src/compiled-loader.tsx +70 -34
  80. package/src/css-loader.tsx +9 -5
  81. package/src/extract-plugin.tsx +4 -3
  82. package/src/index.tsx +1 -0
  83. package/src/types.tsx +5 -60
  84. package/src/{utils/webpack.tsx → utils.tsx} +1 -1
  85. package/dist/__tests__/fixtures/async.js.map +0 -1
  86. package/dist/__tests__/fixtures/babel.d.ts +0 -1
  87. package/dist/__tests__/fixtures/babel.js +0 -14
  88. package/dist/__tests__/fixtures/babel.js.map +0 -1
  89. package/dist/__tests__/fixtures/binding-not-found.js.map +0 -1
  90. package/dist/__tests__/fixtures/important-styles.d.ts +0 -2
  91. package/dist/__tests__/fixtures/important-styles.js +0 -6
  92. package/dist/__tests__/fixtures/important-styles.js.map +0 -1
  93. package/dist/__tests__/fixtures/imports/colors.d.ts +0 -6
  94. package/dist/__tests__/fixtures/imports/colors.js.map +0 -1
  95. package/dist/__tests__/fixtures/imports/css-prop.d.ts +0 -1
  96. package/dist/__tests__/fixtures/imports/css-prop.js +0 -8
  97. package/dist/__tests__/fixtures/imports/css-prop.js.map +0 -1
  98. package/dist/__tests__/fixtures/multiple.d.ts +0 -2
  99. package/dist/__tests__/fixtures/multiple.js +0 -28
  100. package/dist/__tests__/fixtures/multiple.js.map +0 -1
  101. package/dist/__tests__/fixtures/single.d.ts +0 -2
  102. package/dist/__tests__/fixtures/single.js +0 -6
  103. package/dist/__tests__/fixtures/single.js.map +0 -1
  104. package/dist/__tests__/utils/webpack.d.ts +0 -6
  105. package/dist/__tests__/utils/webpack.js +0 -81
  106. package/dist/__tests__/utils/webpack.js.map +0 -1
  107. package/dist/utils/webpack.js.map +0 -1
  108. package/src/__tests__/fixtures/async.js +0 -1
  109. package/src/__tests__/fixtures/babel.js +0 -11
  110. package/src/__tests__/fixtures/important-styles.js +0 -5
  111. package/src/__tests__/fixtures/imports/css-prop.js +0 -4
  112. package/src/__tests__/fixtures/multiple.js +0 -28
  113. package/src/__tests__/fixtures/single.js +0 -5
  114. package/src/__tests__/utils/webpack.tsx +0 -88
@@ -17,7 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.CompiledExtractPlugin = exports.styleSheetName = exports.pluginName = void 0;
18
18
  const css_1 = require("@compiled/css");
19
19
  const utils_1 = require("@compiled/utils");
20
- const webpack_1 = require("./utils/webpack");
20
+ const utils_2 = require("./utils");
21
21
  exports.pluginName = 'CompiledExtractPlugin';
22
22
  exports.styleSheetName = 'compiled-css';
23
23
  /**
@@ -100,22 +100,22 @@ class CompiledExtractPlugin {
100
100
  __classPrivateFieldSet(this, _options, options);
101
101
  }
102
102
  apply(compiler) {
103
- const { RawSource } = webpack_1.getSources(compiler);
103
+ const { RawSource } = utils_2.getSources(compiler);
104
104
  pushNodeModulesExtractLoader(compiler, __classPrivateFieldGet(this, _options));
105
105
  forceCSSIntoOneStyleSheet(compiler);
106
106
  compiler.hooks.compilation.tap(exports.pluginName, (compilation) => {
107
- webpack_1.getNormalModuleHook(compiler, compilation).tap(exports.pluginName, (loaderContext) => {
107
+ utils_2.getNormalModuleHook(compiler, compilation).tap(exports.pluginName, (loaderContext) => {
108
108
  // We add some information here to tell loaders that the plugin has been configured.
109
109
  // Bundling will throw if this is missing (i.e. consumers did not setup correctly).
110
110
  loaderContext[exports.pluginName] = true;
111
111
  });
112
- webpack_1.getOptimizeAssetsHook(compiler, compilation).tap(exports.pluginName, (assets) => {
112
+ utils_2.getOptimizeAssetsHook(compiler, compilation).tap(exports.pluginName, (assets) => {
113
113
  const cssAssets = getCSSAssets(assets);
114
114
  if (cssAssets.length === 0) {
115
115
  return;
116
116
  }
117
117
  const [asset] = cssAssets;
118
- const contents = webpack_1.getAssetSourceContents(asset.source);
118
+ const contents = utils_2.getAssetSourceContents(asset.source);
119
119
  const newSource = new RawSource(css_1.sort(contents));
120
120
  compilation.updateAsset(asset.name, newSource, asset.info);
121
121
  });
@@ -1 +1 @@
1
- {"version":3,"file":"extract-plugin.js","sourceRoot":"","sources":["../src/extract-plugin.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,uCAAqC;AACrC,2CAAyD;AAGzD,6CAKyB;AAEZ,QAAA,UAAU,GAAG,uBAAuB,CAAC;AACrC,QAAA,cAAc,GAAG,cAAc,CAAC;AAE7C;;;;;;GAMG;AACH,MAAM,YAAY,GAAG,CAAC,MAA6B,EAAE,EAAE;IACrD,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;SACvB,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE;QACpB,OAAO,SAAS,CAAC,QAAQ,CAAC,GAAG,sBAAc,MAAM,CAAC,CAAC;IACrD,CAAC,CAAC;SACD,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;AACpF,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,yBAAyB,GAAG,CAAC,QAAkB,EAAE,EAAE;IACvD,MAAM,UAAU,GAAG;QACjB,WAAW,EAAE;YACX,IAAI,EAAE,sBAAc;YACpB,IAAI,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AAC;QACtD,yBAAyB,CAAC,QAAQ,CAAC,CAAC;QAEpC,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,kBAAU,EAAE,CAAC,WAAW,EAAE,EAAE;YACzD,2BAAmB,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC,GAAG,CAAC,kBAAU,EAAE,CAAC,aAAa,EAAE,EAAE;gBAC3E,oFAAoF;gBACpF,mFAAmF;gBAClF,aAAqB,CAAC,kBAAU,CAAC,GAAG,IAAI,CAAC;YAC5C,CAAC,CAAC,CAAC;YAEH,6BAAqB,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC,GAAG,CAAC,kBAAU,EAAE,CAAC,MAAM,EAAE,EAAE;gBACtE,MAAM,SAAS,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;gBACvC,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE;oBAC1B,OAAO;iBACR;gBAED,MAAM,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC;gBAC1B,MAAM,QAAQ,GAAG,8BAAsB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;gBACtD,MAAM,SAAS,GAAG,IAAI,SAAS,CAAC,UAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;gBAEhD,WAAW,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;YAC7D,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAlCD,sDAkCC"}
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export { default, pitch } from './compiled-loader';
2
2
  export { CompiledExtractPlugin } from './extract-plugin';
3
+ export type { CompiledExtractPluginOptions, CompiledLoaderOptions, ResolveOptions } from './types';
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { RuleSetCondition } from 'webpack';
2
- import type { pluginName } from './extract-plugin';
1
+ import type { ResolveOptions, RuleSetCondition } from 'webpack';
2
+ export type { ResolveOptions };
3
3
  export interface CompiledLoaderOptions {
4
4
  /**
5
5
  * Converts your source code into a Compiled component.
@@ -21,64 +21,10 @@ export interface CompiledLoaderOptions {
21
21
  * read [Security](https://compiledcssinjs.com/docs/security) for more information.
22
22
  */
23
23
  nonce?: string;
24
- }
25
- export interface LoaderThis<TOptions = unknown> {
26
- /**
27
- * Query param passed to the loader.
28
- *
29
- * ```
30
- * import '!loader-module?query=params';
31
- * ```
32
- */
33
- resourceQuery: string;
34
- /**
35
- * Absolute path of this file.
36
- */
37
- resourcePath: string;
38
- /**
39
- * Returns the passed in options from a user.
40
- * Optionally validated with a `schema` object.
41
- */
42
- getOptions?: (schema?: {
43
- type: string;
44
- properties: Required<{
45
- [P in keyof TOptions]: {
46
- type: string;
47
- } | {
48
- anyOf: Array<{
49
- type: string;
50
- }>;
51
- };
52
- }>;
53
- }) => TOptions;
54
- /**
55
- * Notifies webpack that this loader run included another file.
56
- * When the other file changes this file will be recompiled.
57
- */
58
- addDependency(path: string): void;
59
- /**
60
- * Marks the loader async.
61
- * Call the return value when the loader has completed.
62
- */
63
- async(): (err: any, result?: string, map?: any) => void;
64
- /**
65
- * Internal access to the current webpack compiler.
66
- */
67
- _compiler: any;
68
- /**
69
- * Internal access to the loaders for this run.
70
- */
71
- loaders: any[];
72
- /**
73
- * Emits an error during the loader run.
74
- *
75
- * @param error
76
- */
77
- emitError(error: Error): void;
78
24
  /**
79
- * When set confirms that the extract plugin has been configured.
25
+ * Override the default `resolve` passed into webpack, which is used to statically evaluate import declarations
80
26
  */
81
- [pluginName]?: true;
27
+ resolve?: ResolveOptions;
82
28
  }
83
29
  export interface CompiledExtractPluginOptions {
84
30
  /**
@@ -1,4 +1,4 @@
1
- import type { Compiler, Compilation as CompilationType, sources } from 'webpack';
1
+ import type { Compilation as CompilationType, Compiler, sources } from 'webpack';
2
2
  /**
3
3
  * Gets the normal module hook for webpack 4 & webpack 5.
4
4
  *
@@ -93,4 +93,4 @@ const toURIComponent = (rule) => {
93
93
  return component;
94
94
  };
95
95
  exports.toURIComponent = toURIComponent;
96
- //# sourceMappingURL=webpack.js.map
96
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.tsx"],"names":[],"mappings":";;;AAEA;;;;GAIG;AACI,MAAM,mBAAmB,GAAG,CACjC,QAAkB,EAClB,WAA4B,EACoB,EAAE;IAClD,MAAM,EAAE,YAAY,EAAE;IACpB,iBAAiB;IACjB,QAAQ,CAAC,OAAO;QAChB,iBAAiB;QACjB,OAAO,CAAC,SAAS,CAAC,CAAC;IAErB,MAAM,gBAAgB,GACpB,YAAY,IAAI,OAAO,YAAY,CAAC,mBAAmB,KAAK,WAAW;QACrE,CAAC,CAAC,iBAAiB;YACjB,YAAY,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC,MAAM;QACtD,CAAC,CAAC,iBAAiB;YACjB,WAAW,CAAC,KAAK,CAAC,kBAAkB,CAAC;IAE3C,OAAO,gBAAgB,CAAC;AAC1B,CAAC,CAAC;AAlBW,QAAA,mBAAmB,uBAkB9B;AAEF;;;;;GAKG;AACI,MAAM,sBAAsB,GAAG,CAAC,WAA2B,EAAU,EAAE;IAC5E,MAAM,MAAM,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC;IACpC,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;QAC9B,OAAO,MAAM,CAAC;KACf;IAED,OAAO,MAAM,CAAC,QAAQ,EAAE,CAAC;AAC3B,CAAC,CAAC;AAPW,QAAA,sBAAsB,0BAOjC;AAEF;;;;;GAKG;AACI,MAAM,qBAAqB,GAAG,CACnC,QAAkB,EAClB,WAA4B,EAC+B,EAAE;IAC7D,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE;IAC5B,iBAAiB;IACjB,QAAQ,CAAC,OAAO;QAChB,iBAAiB;QACjB,OAAO,CAAC,SAAS,CAAC,CAAC;IACrB,MAAM,UAAU,GAAG,OAAO,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;AAEF;;;;;;GAMG;AACI,MAAM,cAAc,GAAG,CAAC,IAAY,EAAU,EAAE;IACrD,MAAM,SAAS,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAEhE,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAJW,QAAA,cAAc,kBAIzB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@compiled/webpack-loader",
3
- "version": "0.6.17",
3
+ "version": "0.7.3",
4
4
  "description": "A familiar and performant compile time CSS-in-JS library for React.",
5
5
  "homepage": "https://compiledcssinjs.com",
6
6
  "bugs": "https://github.com/atlassian-labs/compiled/issues/new?assignees=&labels=bug&template=bug_report.md",
@@ -21,20 +21,21 @@
21
21
  "README.md"
22
22
  ],
23
23
  "dependencies": {
24
- "@babel/core": "^7.15.8",
25
- "@compiled/babel-plugin": "^0.8.0",
26
- "@compiled/babel-plugin-strip-runtime": "^0.6.13",
27
- "@compiled/css": "^0.7.0",
28
- "@compiled/utils": "^0.6.11",
29
- "loader-utils": "^2.0.0",
24
+ "@babel/core": "^7.16.0",
25
+ "@compiled/babel-plugin": "^0.11.1",
26
+ "@compiled/babel-plugin-strip-runtime": "^0.11.1",
27
+ "@compiled/css": "^0.7.1",
28
+ "@compiled/utils": "^0.6.12",
29
+ "enhanced-resolve": "^5.8.3",
30
+ "loader-utils": "^2.0.2",
30
31
  "webpack-sources": "^1.4.3"
31
32
  },
32
33
  "devDependencies": {
33
- "babel-loader": "^8.2.2",
34
+ "babel-loader": "^8.2.3",
34
35
  "css-loader": "^5.2.7",
35
36
  "memfs": "^3.2.4",
36
37
  "mini-css-extract-plugin": "^1.5.0",
37
- "webpack": "^5.58.1"
38
+ "webpack": "^5.61.0"
38
39
  },
39
40
  "peerDependencies": {
40
41
  "webpack": ">= 4.46.0"
@@ -0,0 +1 @@
1
+ import('./common/css-prop');
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+
3
+ import BabelCJS from './lib/babel-cjs';
4
+ import BabelESM from './lib/babel-esm';
5
+
6
+ export const App = (): JSX.Element => (
7
+ <>
8
+ <BabelCJS />
9
+ <BabelESM />
10
+ </>
11
+ );
@@ -1,5 +1,6 @@
1
+ /** @jsx jsx */
2
+ import { jsx, styled } from '@compiled/react';
1
3
  import React from 'react';
2
- import { styled } from '@compiled/react';
3
4
 
4
5
  const height = '9rem';
5
6
 
@@ -1,6 +1,7 @@
1
- export const purple = 'purple';
2
- export const blueviolet = 'blueviolet';
3
1
  export const blue = 'blue';
4
- export const red = 'red';
2
+ export const blueviolet = 'blueviolet';
3
+ export const coral = 'coral';
4
+ export const purple = 'purple';
5
5
  export const orange = 'orange';
6
+ export const red = 'red';
6
7
  export const yellow = 'yellow';
@@ -0,0 +1,8 @@
1
+ /** @jsx jsx */
2
+ import { jsx } from '@compiled/react';
3
+
4
+ import { coral } from './colors';
5
+
6
+ export const Coral = (): JSX.Element => (
7
+ <div css={{ color: coral, border: `2px solid ${coral}` }} />
8
+ );
@@ -0,0 +1,7 @@
1
+ /** @jsx jsx */
2
+ import { jsx, css } from '@compiled/react';
3
+
4
+ // @ts-expect-error
5
+ const styles = css(false);
6
+
7
+ export const App = (): JSX.Element => <div css={styles} />;
@@ -0,0 +1,6 @@
1
+ /** @jsx jsx */
2
+ import { jsx } from '@compiled/react';
3
+
4
+ const Component = (): JSX.Element => <div css={{ fontSize: '12!important', color: 'blue' }} />;
5
+
6
+ export default Component;
@@ -0,0 +1,3 @@
1
+ declare const Component: () => JSX.Element;
2
+
3
+ export default Component;
@@ -0,0 +1,3 @@
1
+ declare const Component: () => JSX.Element;
2
+
3
+ export default Component;
@@ -0,0 +1,5 @@
1
+ import { css } from '@compiled/react';
2
+
3
+ export const styles = css({
4
+ color: 'indigo',
5
+ });
@@ -0,0 +1,5 @@
1
+ import { css } from '@compiled/react';
2
+
3
+ export const styles = css({
4
+ color: 'blue',
5
+ });
@@ -0,0 +1,8 @@
1
+ /** @jsx jsx */
2
+ // @ts-ignore This is a bug where the meta is not updated for the new file import
3
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
4
+ import { jsx, css } from '@compiled/react';
5
+ // @ts-expect-error
6
+ import { styles } from 'loader-alias';
7
+
8
+ export const App = (): JSX.Element => <div css={styles} />;
@@ -0,0 +1,14 @@
1
+ /** @jsx jsx */
2
+ import { jsx, styled } from '@compiled/react';
3
+ import { Fragment } from 'react';
4
+
5
+ const Styled = styled.div({
6
+ color: 'blue',
7
+ });
8
+
9
+ export const App = (): JSX.Element => (
10
+ <Fragment>
11
+ <div css={{ fontSize: 14 }} />
12
+ <Styled />
13
+ </Fragment>
14
+ );
@@ -0,0 +1 @@
1
+ console.log('Hello world!');
@@ -0,0 +1,39 @@
1
+ /** @jsx jsx */
2
+ import { jsx, css, styled } from '@compiled/react';
3
+ import { Fragment } from 'react';
4
+
5
+ import { blueviolet, blue, orange, purple, red, yellow } from './common/colors';
6
+ // @ts-expect-error ↓↓↓ This should not have their styles extracted ↓↓↓
7
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
8
+ import { Coral } from './common/css-prop';
9
+
10
+ export const Styled = styled.span`
11
+ color: ${blueviolet};
12
+
13
+ :focus {
14
+ color: ${purple};
15
+ }
16
+
17
+ :hover {
18
+ color: ${blue};
19
+ }
20
+ `;
21
+
22
+ const styles = css`
23
+ color: ${red};
24
+
25
+ :focus {
26
+ color: ${orange};
27
+ }
28
+
29
+ :hover {
30
+ color: ${yellow};
31
+ }
32
+ `;
33
+
34
+ export const App = (): JSX.Element => (
35
+ <Fragment>
36
+ <div css={styles} />
37
+ <Styled />
38
+ </Fragment>
39
+ );
@@ -0,0 +1,8 @@
1
+ /** @jsx jsx */
2
+ // @ts-expect-error This is a bug where the meta is not updated for the new file import
3
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
4
+ import { jsx, css } from '@compiled/react';
5
+ // @ts-expect-error
6
+ import { styles } from 'webpack-alias';
7
+
8
+ export const App = (): JSX.Element => <div css={styles} />;
@@ -1,53 +1,84 @@
1
- import loader from '../index';
1
+ import { join } from 'path';
2
2
 
3
- const getLoader = (opts: { addDependency: jest.Mock; callback: jest.Mock }) =>
4
- loader.bind({
5
- async: () => opts.callback,
6
- resourcePath: '/projects/index.js',
7
- addDependency: opts.addDependency,
8
- getOptions: () => ({ importReact: false }),
9
- });
3
+ import { bundle as bundleEntry } from './test-utils';
4
+ import type { BundleOptions } from './test-utils';
10
5
 
11
- describe('webpack loader', () => {
12
- it('should bail out early if the file has no compiled in it', async () => {
13
- const callback = jest.fn();
14
- const loader = getLoader({ addDependency: jest.fn(), callback });
6
+ // We are testing in both modes, because the initial custom resolver implementation (i.e. this.getResolve) only works
7
+ // in production
8
+ describe.each<'development' | 'production'>(['development', 'production'])(
9
+ 'webpack loader in %s mode',
10
+ (mode) => {
11
+ const fixturesPath = join(__dirname, '..', '__fixtures__');
15
12
 
16
- await loader('console.log(undefined);');
13
+ const bundle = (entry: string, options: Omit<BundleOptions, 'mode'> = {}) =>
14
+ bundleEntry(entry, {
15
+ ...options,
16
+ mode,
17
+ });
17
18
 
18
- expect(callback).toHaveBeenCalled();
19
- });
19
+ it('does not transform files that do not contain @compiled/react', async () => {
20
+ const assets = await bundle(join(fixturesPath, 'no-compiled-styles.ts'));
20
21
 
21
- it('should transform code if compiled has been found', async () => {
22
- const callback = jest.fn();
23
- const loader = getLoader({ addDependency: jest.fn(), callback });
24
- const code = `import '@compiled/react';`;
22
+ if (mode === 'development') {
23
+ expect(assets['main.js']).toInclude("console.log('Hello world!');");
24
+ } else {
25
+ expect(assets['main.js']).toMatchInlineSnapshot(`"console.log(\\"Hello world!\\");"`);
26
+ }
27
+ });
25
28
 
26
- await loader(code);
29
+ it('transforms local styles', async () => {
30
+ const assets = await bundle(join(fixturesPath, 'local-styles.tsx'));
27
31
 
28
- expect(callback).toHaveBeenCalled();
29
- });
32
+ expect(assets['main.js']).toIncludeMultiple([
33
+ '._1wybdlk8{font-size:14px}',
34
+ '._syaz13q2{color:blue}',
35
+ ]);
36
+ });
30
37
 
31
- it('should callback with transformed code', async () => {
32
- const callback = jest.fn();
33
- const loader = getLoader({ addDependency: jest.fn(), callback });
38
+ it('transforms styles imported through a relative import', async () => {
39
+ const assets = await bundle(join(fixturesPath, 'relative-styles.tsx'));
34
40
 
35
- await loader(`import '@compiled/react';`);
41
+ expect(assets['main.js']).toIncludeMultiple([
42
+ '._syaz5scu{color:red}',
43
+ '._syazmu8g{color:blueviolet}',
44
+ '._f8pjruxl:focus{color:orange}',
45
+ '._f8pj1cnh:focus{color:purple}',
46
+ '._30l31gy6:hover{color:yellow}',
47
+ '._30l313q2:hover{color:blue}',
48
+ ]);
36
49
 
37
- expect(callback.mock.calls[0][0]).toBe(null);
38
- expect(callback.mock.calls[0][1]).toMatchInlineSnapshot(`
39
- "/* index.js generated by @compiled/babel-plugin v0.0.0 */
50
+ // not.toIncludeMultiple does not work as intended
51
+ expect(assets['main.js']).not.toInclude('{border:2px solid coral}');
52
+ expect(assets['main.js']).not.toInclude('{color:coral}');
53
+ });
40
54
 
41
- import { ax, ix, CC, CS } from \\"@compiled/react/runtime\\";"
42
- `);
43
- });
55
+ it('transforms styles imported through a webpack alias', async () => {
56
+ const assets = await bundle(join(fixturesPath, 'webpack-alias.tsx'));
44
57
 
45
- it('should callback on error', async () => {
46
- const callback = jest.fn();
47
- const loader = getLoader({ addDependency: jest.fn(), callback });
58
+ expect(assets['main.js']).toInclude('._syaz13q2{color:blue}');
59
+ });
48
60
 
49
- await loader(`import '@compiled/react'; asdasd`);
61
+ it('transforms styles imported through an overridden resolve configuration', async () => {
62
+ const assets = await bundle(join(fixturesPath, 'loader-alias.tsx'), {
63
+ resolve: {
64
+ // This alias will be put into the compiled plugin options, but not the webpack resolve configuration
65
+ alias: {
66
+ 'loader-alias': join(fixturesPath, 'lib', 'loader-alias.ts'),
67
+ },
68
+ },
69
+ });
50
70
 
51
- expect(callback.mock.calls[0][0]).toBeDefined();
52
- });
53
- });
71
+ expect(assets['main.js']).toInclude('._syaz1if8{color:indigo}');
72
+ });
73
+
74
+ it('fails when using unrecognised compiled syntax', async () => {
75
+ await expect(bundle(join(fixturesPath, 'compiled-error.tsx'))).rejects.toEqual([
76
+ expect.objectContaining({
77
+ message: expect.stringContaining(
78
+ "BooleanLiteral isn't a supported CSS type - try using an object or string"
79
+ ),
80
+ }),
81
+ ]);
82
+ });
83
+ }
84
+ );