@atlaspack/transformer-js 3.2.3-canary.357 → 3.2.3-canary.359

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.
@@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+ exports.loadCompiledCssInJsConfig = loadCompiledCssInJsConfig;
8
+ exports.loadTokensConfig = loadTokensConfig;
7
9
  function _buildCache() {
8
10
  const data = require("@atlaspack/build-cache");
9
11
  _buildCache = function () {
@@ -82,6 +84,13 @@ function _featureFlags() {
82
84
  };
83
85
  return data;
84
86
  }
87
+ function _path() {
88
+ const data = _interopRequireWildcard(require("path"));
89
+ _path = function () {
90
+ return data;
91
+ };
92
+ return data;
93
+ }
85
94
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
86
95
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
87
96
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -180,6 +189,31 @@ const SCRIPT_ERRORS = {
180
189
 
181
190
  // NOTE: Make sure this is in sync with the TypeScript definition in the @atlaspack/macros package.
182
191
 
192
+ const TOKENS_CONFIG_SCHEMA = {
193
+ type: 'object',
194
+ properties: {
195
+ shouldUseAutoFallback: {
196
+ type: 'boolean'
197
+ },
198
+ shouldForceAutoFallback: {
199
+ type: 'boolean'
200
+ },
201
+ forceAutoFallbackExemptions: {
202
+ type: 'array',
203
+ items: {
204
+ type: 'string'
205
+ }
206
+ },
207
+ defaultTheme: {
208
+ type: 'string',
209
+ enum: ['light', 'legacy-light']
210
+ },
211
+ tokenDataPath: {
212
+ type: 'string'
213
+ }
214
+ },
215
+ additionalProperties: false
216
+ };
183
217
  async function legacyDetemineJsxConfig(config, options) {
184
218
  let packageJson = await config.getPackage();
185
219
  let isJSX, jsxPragma, jsxPragmaFrag, jsxImportSource, automaticJSXRuntime, reactRefresh;
@@ -239,6 +273,47 @@ async function legacyDetemineJsxConfig(config, options) {
239
273
  reactRefresh
240
274
  };
241
275
  }
276
+ async function loadTokensConfig(config, options) {
277
+ const conf = await config.getConfigFrom(options.projectRoot + '/index', [], {
278
+ packageKey: '@atlaspack/transformer-tokens'
279
+ });
280
+ if (conf && conf.contents) {
281
+ _utils().validateSchema.diagnostic(TOKENS_CONFIG_SCHEMA, {
282
+ data: conf.contents,
283
+ source: () => options.inputFS.readFileSync(conf.filePath, 'utf8'),
284
+ filePath: conf.filePath,
285
+ prependKey: `/${(0, _diagnostic().encodeJSONKeyComponent)('@atlaspack/transformer-tokens')}`
286
+ }, '@atlaspack/transformer-tokens', 'Invalid config for @atlaspack/transformer-tokens');
287
+
288
+ // @ts-expect-error TS2339
289
+ const tokensConfig = conf.contents;
290
+ let resolvedConfig = {
291
+ shouldUseAutoFallback: tokensConfig.shouldUseAutoFallback ?? true,
292
+ shouldForceAutoFallback: tokensConfig.shouldForceAutoFallback ?? true,
293
+ forceAutoFallbackExemptions: tokensConfig.forceAutoFallbackExemptions ?? [],
294
+ defaultTheme: tokensConfig.defaultTheme ?? 'light',
295
+ tokenDataPath: _path().default.join(options.projectRoot, tokensConfig.tokenDataPath)
296
+ };
297
+ return resolvedConfig;
298
+ }
299
+ }
300
+ async function loadCompiledCssInJsConfig(config, options) {
301
+ var _contents$importSourc;
302
+ const conf = await config.getConfigFrom((0, _path().join)(options.projectRoot, 'index'), ['.compiledcssrc', '.compiledcssrc.json'], {
303
+ packageKey: '@atlaspack/transformer-compiled-css-in-js'
304
+ });
305
+ const contents = {
306
+ configPath: conf === null || conf === void 0 ? void 0 : conf.filePath,
307
+ importSources: ['@compiled/react', '@atlaskit/css']
308
+ };
309
+ Object.assign(contents, conf === null || conf === void 0 ? void 0 : conf.contents);
310
+ if (!((_contents$importSourc = contents.importSources) !== null && _contents$importSourc !== void 0 && _contents$importSourc.includes('@compiled/react'))) {
311
+ var _contents$importSourc2;
312
+ (_contents$importSourc2 = contents.importSources) === null || _contents$importSourc2 === void 0 || _contents$importSourc2.push('@compiled/react');
313
+ }
314
+ contents.extract = contents.extract && options.mode !== 'development';
315
+ return contents;
316
+ }
242
317
  var _default = exports.default = new (_plugin().Transformer)({
243
318
  async loadConfig({
244
319
  config,
@@ -330,6 +405,8 @@ var _default = exports.default = new (_plugin().Transformer)({
330
405
  }
331
406
  }
332
407
  config.invalidateOnEnvChange('SYNC_DYNAMIC_IMPORT_CONFIG');
408
+ const tokensConfig = (0, _featureFlags().getFeatureFlag)('coreTokensAndCompiledCssInJsTransform') ? await loadTokensConfig(config, options) : undefined;
409
+ const compiledCssInJsConfig = (0, _featureFlags().getFeatureFlag)('coreTokensAndCompiledCssInJsTransform') ? await loadCompiledCssInJsConfig(config, options) : undefined;
333
410
  if (conf && conf.contents) {
334
411
  var _conf$contents2, _conf$contents3, _conf$contents4, _conf$contents5, _conf$contents6;
335
412
  addReactDisplayName = ((_conf$contents2 = conf.contents) === null || _conf$contents2 === void 0 ? void 0 : _conf$contents2.addReactDisplayName) ?? addReactDisplayName;
@@ -363,7 +440,9 @@ var _default = exports.default = new (_plugin().Transformer)({
363
440
  syncDynamicImportConfig,
364
441
  enableReactAsyncImportLift,
365
442
  reactAsyncLiftByDefault,
366
- reactAsyncLiftReportLevel
443
+ reactAsyncLiftReportLevel,
444
+ tokensConfig: tokensConfig,
445
+ compiledCssInJsConfig: compiledCssInJsConfig
367
446
  };
368
447
  },
369
448
  async transform({
@@ -475,7 +554,9 @@ var _default = exports.default = new (_plugin().Transformer)({
475
554
  // @ts-expect-error TS2339
476
555
  conditions,
477
556
  // @ts-expect-error TS2339
478
- magic_comments
557
+ magic_comments,
558
+ // @ts-expect-error TS2339
559
+ style_rules
479
560
  } = await (_rust().transformAsync || _rust().transform)({
480
561
  filename: asset.filePath,
481
562
  code,
@@ -527,6 +608,9 @@ var _default = exports.default = new (_plugin().Transformer)({
527
608
  react_async_lift_by_default: Boolean(config.reactAsyncLiftByDefault),
528
609
  react_async_lift_report_level: String(config.reactAsyncLiftReportLevel),
529
610
  sync_dynamic_import_config: config.syncDynamicImportConfig,
611
+ enable_tokens_and_compiled_css_in_js_transform: (0, _featureFlags().getFeatureFlag)('coreTokensAndCompiledCssInJsTransform'),
612
+ tokens_config: config.tokensConfig,
613
+ compiled_css_in_js_config: config.compiledCssInJsConfig,
530
614
  callMacro: asset.isSource ? async (err, src, exportName, args, loc) => {
531
615
  let mod;
532
616
  try {
@@ -636,6 +720,9 @@ var _default = exports.default = new (_plugin().Transformer)({
636
720
  if ((0, _featureFlags().getFeatureFlag)('conditionalBundlingApi')) {
637
721
  asset.meta.conditions = conditions;
638
722
  }
723
+ if (style_rules) {
724
+ asset.meta.styleRules = style_rules;
725
+ }
639
726
  if (is_constant_module) {
640
727
  asset.meta.isConstantModule = true;
641
728
  }
@@ -1,3 +1,14 @@
1
+ import type { Config, PluginOptions } from '@atlaspack/types';
1
2
  import { Transformer } from '@atlaspack/plugin';
3
+ import { type CompiledCssInJsConfigPlugin } from '@atlaspack/rust/index';
4
+ type AtlaskitTokensConfigPartial = {
5
+ shouldUseAutoFallback?: boolean;
6
+ shouldForceAutoFallback?: boolean;
7
+ forceAutoFallbackExemptions?: Array<string>;
8
+ defaultTheme?: 'light' | 'legacy-light';
9
+ tokenDataPath: string;
10
+ };
11
+ export declare function loadTokensConfig(config: Config, options: PluginOptions): Promise<Required<AtlaskitTokensConfigPartial> | undefined>;
12
+ export declare function loadCompiledCssInJsConfig(config: Config, options: PluginOptions): Promise<CompiledCssInJsConfigPlugin>;
2
13
  declare const _default: Transformer<unknown>;
3
14
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/transformer-js",
3
- "version": "3.2.3-canary.357+e15fb6c88",
3
+ "version": "3.2.3-canary.359+53da21632",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -24,14 +24,14 @@
24
24
  "src"
25
25
  ],
26
26
  "dependencies": {
27
- "@atlaspack/build-cache": "2.13.3-canary.425+e15fb6c88",
28
- "@atlaspack/diagnostic": "2.14.1-canary.425+e15fb6c88",
29
- "@atlaspack/feature-flags": "2.14.1-canary.425+e15fb6c88",
30
- "@atlaspack/plugin": "2.14.5-canary.357+e15fb6c88",
31
- "@atlaspack/rust": "3.2.1-canary.357+e15fb6c88",
32
- "@atlaspack/source-map": "3.2.4-canary.4136+e15fb6c88",
33
- "@atlaspack/utils": "2.14.5-canary.357+e15fb6c88",
34
- "@atlaspack/workers": "2.14.5-canary.357+e15fb6c88",
27
+ "@atlaspack/build-cache": "2.13.3-canary.427+53da21632",
28
+ "@atlaspack/diagnostic": "2.14.1-canary.427+53da21632",
29
+ "@atlaspack/feature-flags": "2.14.1-canary.427+53da21632",
30
+ "@atlaspack/plugin": "2.14.5-canary.359+53da21632",
31
+ "@atlaspack/rust": "3.2.1-canary.359+53da21632",
32
+ "@atlaspack/source-map": "3.2.4-canary.4138+53da21632",
33
+ "@atlaspack/utils": "2.14.5-canary.359+53da21632",
34
+ "@atlaspack/workers": "2.14.5-canary.359+53da21632",
35
35
  "@swc/helpers": "^0.5.15",
36
36
  "browserslist": "^4.6.6",
37
37
  "nullthrows": "^1.1.1",
@@ -42,5 +42,5 @@
42
42
  "@atlaspack/core": "2.31.2"
43
43
  },
44
44
  "type": "commonjs",
45
- "gitHead": "e15fb6c885c6354c6c02283de35ce18abc8c9e18"
45
+ "gitHead": "53da216320e19c9b71b001386eb420d05f111db8"
46
46
  }
@@ -17,6 +17,7 @@ import {
17
17
  transformAsync,
18
18
  determineJsxConfiguration,
19
19
  } from '@atlaspack/rust';
20
+ import {type CompiledCssInJsConfigPlugin} from '@atlaspack/rust/index';
20
21
  import invariant from 'assert';
21
22
  import browserslist from 'browserslist';
22
23
  import semver from 'semver';
@@ -28,6 +29,7 @@ import ThrowableDiagnostic, {
28
29
  import {validateSchema, remapSourceLocation, globMatch} from '@atlaspack/utils';
29
30
  import pkg from '../package.json';
30
31
  import {getFeatureFlag} from '@atlaspack/feature-flags';
32
+ import path, {join} from 'path';
31
33
 
32
34
  const JSX_EXTENSIONS = {
33
35
  jsx: true,
@@ -194,6 +196,31 @@ type MacroContext = {
194
196
  invalidateOnBuild(): void;
195
197
  };
196
198
 
199
+ type AtlaskitTokensConfigPartial = {
200
+ shouldUseAutoFallback?: boolean;
201
+ shouldForceAutoFallback?: boolean;
202
+ forceAutoFallbackExemptions?: Array<string>;
203
+ defaultTheme?: 'light' | 'legacy-light';
204
+ tokenDataPath: string;
205
+ };
206
+
207
+ type AtlaskitTokensConfig = Required<AtlaskitTokensConfigPartial>;
208
+
209
+ const TOKENS_CONFIG_SCHEMA = {
210
+ type: 'object',
211
+ properties: {
212
+ shouldUseAutoFallback: {type: 'boolean'},
213
+ shouldForceAutoFallback: {type: 'boolean'},
214
+ forceAutoFallbackExemptions: {
215
+ type: 'array',
216
+ items: {type: 'string'},
217
+ },
218
+ defaultTheme: {type: 'string', enum: ['light', 'legacy-light']},
219
+ tokenDataPath: {type: 'string'},
220
+ },
221
+ additionalProperties: false,
222
+ } as const;
223
+
197
224
  interface JsxConfig {
198
225
  isJSX: boolean | undefined;
199
226
  jsxPragma: string | undefined;
@@ -310,6 +337,67 @@ async function legacyDetemineJsxConfig(
310
337
  };
311
338
  }
312
339
 
340
+ export async function loadTokensConfig(config: Config, options: PluginOptions) {
341
+ const conf = await config.getConfigFrom(options.projectRoot + '/index', [], {
342
+ packageKey: '@atlaspack/transformer-tokens',
343
+ });
344
+
345
+ if (conf && conf.contents) {
346
+ validateSchema.diagnostic(
347
+ TOKENS_CONFIG_SCHEMA,
348
+ {
349
+ data: conf.contents,
350
+ source: () => options.inputFS.readFileSync(conf.filePath, 'utf8'),
351
+ filePath: conf.filePath,
352
+ prependKey: `/${encodeJSONKeyComponent('@atlaspack/transformer-tokens')}`,
353
+ },
354
+ '@atlaspack/transformer-tokens',
355
+ 'Invalid config for @atlaspack/transformer-tokens',
356
+ );
357
+
358
+ // @ts-expect-error TS2339
359
+ const tokensConfig: AtlaskitTokensConfigPartial = conf.contents;
360
+
361
+ let resolvedConfig: AtlaskitTokensConfig = {
362
+ shouldUseAutoFallback: tokensConfig.shouldUseAutoFallback ?? true,
363
+ shouldForceAutoFallback: tokensConfig.shouldForceAutoFallback ?? true,
364
+ forceAutoFallbackExemptions:
365
+ tokensConfig.forceAutoFallbackExemptions ?? [],
366
+ defaultTheme: tokensConfig.defaultTheme ?? 'light',
367
+ tokenDataPath: path.join(options.projectRoot, tokensConfig.tokenDataPath),
368
+ };
369
+ return resolvedConfig;
370
+ }
371
+ }
372
+
373
+ export async function loadCompiledCssInJsConfig(
374
+ config: Config,
375
+ options: PluginOptions,
376
+ ): Promise<CompiledCssInJsConfigPlugin> {
377
+ const conf = await config.getConfigFrom<CompiledCssInJsConfigPlugin>(
378
+ join(options.projectRoot, 'index'),
379
+ ['.compiledcssrc', '.compiledcssrc.json'],
380
+ {
381
+ packageKey: '@atlaspack/transformer-compiled-css-in-js',
382
+ },
383
+ );
384
+
385
+ const contents: CompiledCssInJsConfigPlugin = {
386
+ configPath: conf?.filePath,
387
+ importSources: ['@compiled/react', '@atlaskit/css'],
388
+ };
389
+
390
+ Object.assign(contents, conf?.contents);
391
+
392
+ if (!contents.importSources?.includes('@compiled/react')) {
393
+ contents.importSources?.push('@compiled/react');
394
+ }
395
+
396
+ contents.extract = contents.extract && options.mode !== 'development';
397
+
398
+ return contents;
399
+ }
400
+
313
401
  export default new Transformer({
314
402
  async loadConfig({config, options}) {
315
403
  let conf = await config.getConfigFrom<JsTransformerConfig>(
@@ -456,6 +544,16 @@ export default new Transformer({
456
544
 
457
545
  config.invalidateOnEnvChange('SYNC_DYNAMIC_IMPORT_CONFIG');
458
546
 
547
+ const tokensConfig = getFeatureFlag('coreTokensAndCompiledCssInJsTransform')
548
+ ? await loadTokensConfig(config, options)
549
+ : undefined;
550
+
551
+ const compiledCssInJsConfig = getFeatureFlag(
552
+ 'coreTokensAndCompiledCssInJsTransform',
553
+ )
554
+ ? await loadCompiledCssInJsConfig(config, options)
555
+ : undefined;
556
+
459
557
  if (conf && conf.contents) {
460
558
  addReactDisplayName =
461
559
  conf.contents?.addReactDisplayName ?? addReactDisplayName;
@@ -492,6 +590,8 @@ export default new Transformer({
492
590
  enableReactAsyncImportLift,
493
591
  reactAsyncLiftByDefault,
494
592
  reactAsyncLiftReportLevel,
593
+ tokensConfig: tokensConfig,
594
+ compiledCssInJsConfig: compiledCssInJsConfig,
495
595
  };
496
596
  },
497
597
  async transform({asset, config, options, logger}) {
@@ -621,6 +721,8 @@ export default new Transformer({
621
721
  conditions,
622
722
  // @ts-expect-error TS2339
623
723
  magic_comments,
724
+ // @ts-expect-error TS2339
725
+ style_rules,
624
726
  } = await (transformAsync || transform)({
625
727
  filename: asset.filePath,
626
728
  code,
@@ -690,6 +792,11 @@ export default new Transformer({
690
792
  react_async_lift_by_default: Boolean(config.reactAsyncLiftByDefault),
691
793
  react_async_lift_report_level: String(config.reactAsyncLiftReportLevel),
692
794
  sync_dynamic_import_config: config.syncDynamicImportConfig,
795
+ enable_tokens_and_compiled_css_in_js_transform: getFeatureFlag(
796
+ 'coreTokensAndCompiledCssInJsTransform',
797
+ ),
798
+ tokens_config: config.tokensConfig,
799
+ compiled_css_in_js_config: config.compiledCssInJsConfig,
693
800
  callMacro: asset.isSource
694
801
  ? async (err: any, src: any, exportName: any, args: any, loc: any) => {
695
802
  let mod;
@@ -813,6 +920,10 @@ export default new Transformer({
813
920
  asset.meta.conditions = conditions;
814
921
  }
815
922
 
923
+ if (style_rules) {
924
+ asset.meta.styleRules = style_rules;
925
+ }
926
+
816
927
  if (is_constant_module) {
817
928
  asset.meta.isConstantModule = true;
818
929
  }