@wyw-in-js/transform 0.1.1 → 0.2.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.
Files changed (142) hide show
  1. package/esm/index.js +4 -1
  2. package/esm/index.js.map +1 -1
  3. package/esm/options/loadBabelOptions.js +1 -1
  4. package/esm/options/loadBabelOptions.js.map +1 -1
  5. package/esm/plugins/babel-transform.js +2 -2
  6. package/esm/plugins/babel-transform.js.map +1 -1
  7. package/esm/plugins/collector.js +4 -4
  8. package/esm/plugins/collector.js.map +1 -1
  9. package/esm/plugins/preeval.js +11 -11
  10. package/esm/plugins/preeval.js.map +1 -1
  11. package/esm/plugins/shaker.js +5 -5
  12. package/esm/plugins/shaker.js.map +1 -1
  13. package/esm/shaker.js +2 -2
  14. package/esm/shaker.js.map +1 -1
  15. package/esm/transform/Entrypoint.helpers.js +1 -2
  16. package/esm/transform/Entrypoint.helpers.js.map +1 -1
  17. package/esm/transform/Entrypoint.js +4 -4
  18. package/esm/transform/Entrypoint.js.map +1 -1
  19. package/esm/transform/generators/collect.js +3 -2
  20. package/esm/transform/generators/collect.js.map +1 -1
  21. package/esm/transform/generators/evalFile.js +6 -6
  22. package/esm/transform/generators/evalFile.js.map +1 -1
  23. package/esm/transform/generators/extract.js +18 -14
  24. package/esm/transform/generators/extract.js.map +1 -1
  25. package/esm/transform/generators/transform.js +2 -2
  26. package/esm/transform/generators/transform.js.map +1 -1
  27. package/esm/transform/generators/workflow.js +3 -3
  28. package/esm/transform/generators/workflow.js.map +1 -1
  29. package/esm/transform/helpers/{loadLinariaOptions.js → loadWywOptions.js} +5 -5
  30. package/esm/transform/helpers/loadWywOptions.js.map +1 -0
  31. package/esm/transform.js +11 -10
  32. package/esm/transform.js.map +1 -1
  33. package/esm/types.js.map +1 -1
  34. package/esm/utils/ShakerMetadata.js +1 -1
  35. package/esm/utils/ShakerMetadata.js.map +1 -1
  36. package/esm/utils/{addIdentifierToLinariaPreval.js → addIdentifierToWywPreval.js} +10 -10
  37. package/esm/utils/addIdentifierToWywPreval.js.map +1 -0
  38. package/esm/utils/collectExportsAndImports.js +141 -53
  39. package/esm/utils/collectExportsAndImports.js.map +1 -1
  40. package/esm/utils/collectTemplateDependencies.js +2 -2
  41. package/esm/utils/collectTemplateDependencies.js.map +1 -1
  42. package/esm/utils/getTagProcessor.js +1 -1
  43. package/esm/utils/getTagProcessor.js.map +1 -1
  44. package/esm/utils/hasWywPreval.js +7 -0
  45. package/esm/utils/hasWywPreval.js.map +1 -0
  46. package/lib/index.js +28 -4
  47. package/lib/index.js.map +1 -1
  48. package/lib/options/loadBabelOptions.js +1 -1
  49. package/lib/options/loadBabelOptions.js.map +1 -1
  50. package/lib/plugins/babel-transform.js +2 -2
  51. package/lib/plugins/babel-transform.js.map +1 -1
  52. package/lib/plugins/collector.js +4 -4
  53. package/lib/plugins/collector.js.map +1 -1
  54. package/lib/plugins/preeval.js +11 -11
  55. package/lib/plugins/preeval.js.map +1 -1
  56. package/lib/plugins/shaker.js +5 -5
  57. package/lib/plugins/shaker.js.map +1 -1
  58. package/lib/shaker.js +2 -2
  59. package/lib/shaker.js.map +1 -1
  60. package/lib/transform/Entrypoint.helpers.js +1 -2
  61. package/lib/transform/Entrypoint.helpers.js.map +1 -1
  62. package/lib/transform/Entrypoint.js +4 -4
  63. package/lib/transform/Entrypoint.js.map +1 -1
  64. package/lib/transform/generators/collect.js +1 -1
  65. package/lib/transform/generators/collect.js.map +1 -1
  66. package/lib/transform/generators/evalFile.js +6 -6
  67. package/lib/transform/generators/evalFile.js.map +1 -1
  68. package/lib/transform/generators/extract.js +18 -14
  69. package/lib/transform/generators/extract.js.map +1 -1
  70. package/lib/transform/generators/transform.js +2 -2
  71. package/lib/transform/generators/transform.js.map +1 -1
  72. package/lib/transform/generators/workflow.js +3 -3
  73. package/lib/transform/generators/workflow.js.map +1 -1
  74. package/lib/transform/helpers/{loadLinariaOptions.js → loadWywOptions.js} +6 -6
  75. package/lib/transform/helpers/loadWywOptions.js.map +1 -0
  76. package/lib/transform/helpers/withDefaultServices.js +2 -2
  77. package/lib/transform/helpers/withDefaultServices.js.map +1 -1
  78. package/lib/transform.js +11 -10
  79. package/lib/transform.js.map +1 -1
  80. package/lib/types.js.map +1 -1
  81. package/lib/utils/ShakerMetadata.js +1 -1
  82. package/lib/utils/ShakerMetadata.js.map +1 -1
  83. package/lib/utils/{addIdentifierToLinariaPreval.js → addIdentifierToWywPreval.js} +12 -12
  84. package/lib/utils/addIdentifierToWywPreval.js.map +1 -0
  85. package/lib/utils/collectExportsAndImports.js +141 -53
  86. package/lib/utils/collectExportsAndImports.js.map +1 -1
  87. package/lib/utils/collectTemplateDependencies.js +2 -2
  88. package/lib/utils/collectTemplateDependencies.js.map +1 -1
  89. package/lib/utils/getTagProcessor.js +2 -2
  90. package/lib/utils/getTagProcessor.js.map +1 -1
  91. package/lib/utils/hasWywPreval.js +13 -0
  92. package/lib/utils/hasWywPreval.js.map +1 -0
  93. package/lib/vm/createVmContext.js +2 -2
  94. package/lib/vm/createVmContext.js.map +1 -1
  95. package/package.json +24 -21
  96. package/types/index.d.ts +5 -2
  97. package/types/index.js +9 -3
  98. package/types/options/loadBabelOptions.js +1 -1
  99. package/types/plugins/babel-transform.js +2 -2
  100. package/types/plugins/collector.js +4 -4
  101. package/types/plugins/preeval.js +11 -11
  102. package/types/plugins/shaker.js +5 -5
  103. package/types/shaker.js +2 -2
  104. package/types/transform/Entrypoint.d.ts +1 -1
  105. package/types/transform/Entrypoint.helpers.js +3 -3
  106. package/types/transform/Entrypoint.js +4 -4
  107. package/types/transform/generators/collect.js +1 -1
  108. package/types/transform/generators/evalFile.js +7 -7
  109. package/types/transform/generators/extract.js +21 -12
  110. package/types/transform/generators/transform.js +2 -4
  111. package/types/transform/generators/workflow.js +3 -3
  112. package/types/transform/helpers/{loadLinariaOptions.d.ts → loadWywOptions.d.ts} +1 -1
  113. package/types/transform/helpers/{loadLinariaOptions.js → loadWywOptions.js} +19 -19
  114. package/types/transform.d.ts +7 -6
  115. package/types/transform.js +11 -10
  116. package/types/types.d.ts +1 -1
  117. package/types/utils/ShakerMetadata.d.ts +1 -1
  118. package/types/utils/ShakerMetadata.js +1 -1
  119. package/types/utils/addIdentifierToWywPreval.d.ts +4 -0
  120. package/types/utils/{addIdentifierToLinariaPreval.js → addIdentifierToWywPreval.js} +12 -12
  121. package/types/utils/collectExportsAndImports.js +157 -58
  122. package/types/utils/collectTemplateDependencies.d.ts +1 -1
  123. package/types/utils/collectTemplateDependencies.js +2 -2
  124. package/types/utils/getTagProcessor.js +2 -2
  125. package/types/utils/hasWywPreval.d.ts +4 -0
  126. package/types/utils/{hasLinariaPreval.js → hasWywPreval.js} +3 -3
  127. package/esm/transform/helpers/loadLinariaOptions.js.map +0 -1
  128. package/esm/utils/addIdentifierToLinariaPreval.js.map +0 -1
  129. package/esm/utils/findPackageJSON.js +0 -26
  130. package/esm/utils/findPackageJSON.js.map +0 -1
  131. package/esm/utils/hasLinariaPreval.js +0 -7
  132. package/esm/utils/hasLinariaPreval.js.map +0 -1
  133. package/lib/transform/helpers/loadLinariaOptions.js.map +0 -1
  134. package/lib/utils/addIdentifierToLinariaPreval.js.map +0 -1
  135. package/lib/utils/findPackageJSON.js +0 -35
  136. package/lib/utils/findPackageJSON.js.map +0 -1
  137. package/lib/utils/hasLinariaPreval.js +0 -13
  138. package/lib/utils/hasLinariaPreval.js.map +0 -1
  139. package/types/utils/addIdentifierToLinariaPreval.d.ts +0 -4
  140. package/types/utils/findPackageJSON.d.ts +0 -1
  141. package/types/utils/findPackageJSON.js +0 -56
  142. package/types/utils/hasLinariaPreval.d.ts +0 -4
@@ -1 +1 @@
1
- {"version":3,"file":"Entrypoint.js","names":["invariant","BaseEntrypoint","isSuperSet","mergeOnly","EvaluatedEntrypoint","AbortError","BaseAction","UnprocessedEntrypointError","EMPTY_FILE","hasLoop","name","parent","processed","includes","p","parents","found","Entrypoint","evaluated","onSupersedeHandlers","actionsCache","Map","hasLinariaMetadata","supersededWith","transformResultCode","constructor","services","initialCode","only","exports","evaluatedOnly","loadedAndParsed","resolveTasks","dependencies","generation","loadAndParseFn","log","code","undefined","cache","invalidateIfChanged","extend","originalCode","ignored","evaluator","transformedCode","createRoot","loadedCode","created","create","eventEmitter","perf","status","entrypoint","innerCreate","seqId","add","cached","get","changed","mergedOnly","filter","i","isLoop","map","push","supersede","newEntrypoint","addDependency","dependency","delete","source","set","addResolveTask","assertNotSuperseded","assertTransformed","createAction","actionType","data","abortSignal","has","aborted","newAction","entrypointEvent","type","actionIdx","idx","createChild","createEvaluated","exportsProxy","getDependency","getResolveTask","onSupersede","callback","index","indexOf","splice","setTransformResult","res","Boolean","metadata","isNull","newOnlyOrEntrypoint","with","forEach","handler"],"sources":["../../src/transform/Entrypoint.ts"],"sourcesContent":["import { invariant } from 'ts-invariant';\n\nimport type { ParentEntrypoint, ITransformFileResult } from '../types';\n\nimport { BaseEntrypoint } from './BaseEntrypoint';\nimport { isSuperSet, mergeOnly } from './Entrypoint.helpers';\nimport type {\n IEntrypointCode,\n IEntrypointDependency,\n IIgnoredEntrypoint,\n} from './Entrypoint.types';\nimport { EvaluatedEntrypoint } from './EvaluatedEntrypoint';\nimport { AbortError } from './actions/AbortError';\nimport type { ActionByType } from './actions/BaseAction';\nimport { BaseAction } from './actions/BaseAction';\nimport { UnprocessedEntrypointError } from './actions/UnprocessedEntrypointError';\nimport type { Services, ActionTypes, ActionQueueItem } from './types';\n\nconst EMPTY_FILE = '=== empty file ===';\n\nfunction hasLoop(\n name: string,\n parent: ParentEntrypoint,\n processed: string[] = []\n): boolean {\n if (parent.name === name || processed.includes(parent.name)) {\n return true;\n }\n\n for (const p of parent.parents) {\n const found = hasLoop(name, p, [...processed, parent.name]);\n if (found) {\n return found;\n }\n }\n\n return false;\n}\n\nexport class Entrypoint extends BaseEntrypoint {\n public readonly evaluated = false;\n\n public readonly loadedAndParsed: IEntrypointCode | IIgnoredEntrypoint;\n\n protected onSupersedeHandlers: Array<(newEntrypoint: Entrypoint) => void> =\n [];\n\n private actionsCache: Map<\n ActionTypes,\n Map<unknown, BaseAction<ActionQueueItem>>\n > = new Map();\n\n #hasLinariaMetadata: boolean = false;\n\n #supersededWith: Entrypoint | null = null;\n\n #transformResultCode: string | null = null;\n\n private constructor(\n services: Services,\n parents: ParentEntrypoint[],\n public readonly initialCode: string | undefined,\n name: string,\n only: string[],\n exports: Record<string | symbol, unknown> | undefined,\n evaluatedOnly: string[],\n loadedAndParsed?: IEntrypointCode | IIgnoredEntrypoint,\n protected readonly resolveTasks = new Map<\n string,\n Promise<IEntrypointDependency>\n >(),\n protected readonly dependencies = new Map<string, IEntrypointDependency>(),\n generation = 1\n ) {\n super(services, evaluatedOnly, exports, generation, name, only, parents);\n\n this.loadedAndParsed =\n loadedAndParsed ??\n services.loadAndParseFn(\n services,\n name,\n initialCode,\n parents[0]?.log ?? services.log\n );\n\n if (this.loadedAndParsed.code !== undefined) {\n services.cache.invalidateIfChanged(name, this.loadedAndParsed.code);\n }\n\n this.log.extend('source')(\n 'created %s (%o)\\n%s',\n name,\n only,\n this.originalCode || EMPTY_FILE\n );\n }\n\n public get ignored() {\n return this.loadedAndParsed.evaluator === 'ignored';\n }\n\n public get originalCode() {\n return this.loadedAndParsed.code;\n }\n\n public get supersededWith(): Entrypoint | null {\n return this.#supersededWith?.supersededWith ?? this.#supersededWith;\n }\n\n public get transformedCode(): string | null {\n return (\n this.#transformResultCode ?? this.supersededWith?.transformedCode ?? null\n );\n }\n\n public static createRoot(\n services: Services,\n name: string,\n only: string[],\n loadedCode: string | undefined\n ): Entrypoint {\n const created = Entrypoint.create(services, null, name, only, loadedCode);\n invariant(created !== 'loop', 'loop detected');\n\n return created;\n }\n\n /**\n * Creates an entrypoint for the specified file.\n * If there is already an entrypoint for this file, there will be four possible outcomes:\n * 1. If `loadedCode` is specified and is different from the one that was used to create the existing entrypoint,\n * the existing entrypoint will be superseded by a new one and all cached results for it will be invalidated.\n * It can happen if the file was changed and the watcher notified us about it, or we received a new version\n * of the file from a loader whereas the previous one was loaded from the filesystem.\n * The new entrypoint will be returned.\n * 2. If `only` is subset of the existing entrypoint's `only`, the existing entrypoint will be returned.\n * 3. If `only` is superset of the existing entrypoint's `only`, the existing entrypoint will be superseded and the new one will be returned.\n * 4. If a loop is detected, 'ignored' will be returned, the existing entrypoint will be superseded or not depending on the `only` value.\n */\n protected static create(\n services: Services,\n parent: ParentEntrypoint | null,\n name: string,\n only: string[],\n loadedCode: string | undefined\n ): Entrypoint | 'loop' {\n const { cache, eventEmitter } = services;\n return eventEmitter.perf('createEntrypoint', () => {\n const [status, entrypoint] = Entrypoint.innerCreate(\n services,\n parent\n ? {\n evaluated: parent.evaluated,\n log: parent.log,\n name: parent.name,\n parents: parent.parents,\n seqId: parent.seqId,\n }\n : null,\n name,\n only,\n loadedCode\n );\n\n if (status !== 'cached') {\n cache.add('entrypoints', name, entrypoint);\n }\n\n return status === 'loop' ? 'loop' : entrypoint;\n });\n }\n\n private static innerCreate(\n services: Services,\n parent: ParentEntrypoint | null,\n name: string,\n only: string[],\n loadedCode: string | undefined\n ): ['loop' | 'created' | 'cached', Entrypoint] {\n const { cache } = services;\n\n const cached = cache.get('entrypoints', name);\n const changed =\n loadedCode !== undefined\n ? cache.invalidateIfChanged(name, loadedCode)\n : false;\n\n if (!cached?.evaluated && cached?.ignored) {\n return ['cached', cached];\n }\n\n const exports = cached?.exports;\n const evaluatedOnly = cached?.evaluatedOnly ?? [];\n const mergedOnly =\n !changed && cached?.only\n ? mergeOnly(cached.only, only).filter((i) => !evaluatedOnly.includes(i))\n : only;\n\n if (cached?.evaluated) {\n cached.log('is already evaluated with', cached.evaluatedOnly);\n }\n\n if (!changed && cached && !cached.evaluated) {\n const isLoop = parent && hasLoop(name, parent);\n if (isLoop) {\n parent.log('[createEntrypoint] %s is a loop', name);\n }\n\n if (parent && !cached.parents.map((p) => p.name).includes(parent.name)) {\n cached.parents.push(parent);\n }\n\n if (isSuperSet(cached.only, mergedOnly)) {\n cached.log('is cached', name);\n return [isLoop ? 'loop' : 'cached', cached];\n }\n\n cached.log(\n 'is cached, but with different `only` %o (the cached one %o)',\n only,\n cached?.only\n );\n\n return [isLoop ? 'loop' : 'created', cached.supersede(mergedOnly)];\n }\n\n const newEntrypoint = new Entrypoint(\n services,\n parent ? [parent] : [],\n loadedCode,\n name,\n mergedOnly,\n exports,\n evaluatedOnly,\n undefined,\n cached && 'resolveTasks' in cached ? cached.resolveTasks : undefined,\n cached && 'dependencies' in cached ? cached.dependencies : undefined,\n cached ? cached.generation + 1 : 1\n );\n\n if (cached && !cached.evaluated) {\n cached.log('is cached, but with different code');\n cached.supersede(newEntrypoint);\n }\n\n return ['created', newEntrypoint];\n }\n\n public addDependency(dependency: IEntrypointDependency): void {\n this.resolveTasks.delete(dependency.source);\n this.dependencies.set(dependency.source, dependency);\n }\n\n public addResolveTask(\n name: string,\n dependency: Promise<IEntrypointDependency>\n ): void {\n this.resolveTasks.set(name, dependency);\n }\n\n public assertNotSuperseded() {\n if (this.supersededWith) {\n this.log('superseded');\n throw new AbortError('superseded');\n }\n }\n\n public assertTransformed() {\n if (this.transformedCode === null) {\n this.log('not transformed');\n throw new UnprocessedEntrypointError(this.supersededWith ?? this);\n }\n }\n\n public createAction<\n TType extends ActionTypes,\n TAction extends ActionByType<TType>,\n >(\n actionType: TType,\n data: TAction['data'],\n abortSignal: AbortSignal | null = null\n ): BaseAction<TAction> {\n if (!this.actionsCache.has(actionType)) {\n this.actionsCache.set(actionType, new Map());\n }\n\n const cache = this.actionsCache.get(actionType)!;\n const cached = cache.get(data);\n if (cached && !cached.abortSignal?.aborted) {\n return cached as BaseAction<TAction>;\n }\n\n const newAction = new BaseAction<TAction>(\n actionType as TAction['type'],\n this.services,\n this,\n data,\n abortSignal\n );\n\n cache.set(data, newAction);\n\n this.services.eventEmitter.entrypointEvent(this.seqId, {\n type: 'actionCreated',\n actionType,\n actionIdx: newAction.idx,\n });\n\n return newAction;\n }\n\n public createChild(\n name: string,\n only: string[],\n loadedCode?: string\n ): Entrypoint | 'loop' {\n return Entrypoint.create(this.services, this, name, only, loadedCode);\n }\n\n public createEvaluated() {\n const evaluatedOnly = mergeOnly(this.evaluatedOnly, this.only);\n this.log('create EvaluatedEntrypoint for %o', evaluatedOnly);\n\n return new EvaluatedEntrypoint(\n this.services,\n evaluatedOnly,\n this.exportsProxy,\n this.generation + 1,\n this.name,\n this.only,\n this.parents\n );\n }\n\n public getDependency(name: string): IEntrypointDependency | undefined {\n return this.dependencies.get(name);\n }\n\n public getResolveTask(\n name: string\n ): Promise<IEntrypointDependency> | undefined {\n return this.resolveTasks.get(name);\n }\n\n public hasLinariaMetadata() {\n return this.#hasLinariaMetadata;\n }\n\n public onSupersede(callback: (newEntrypoint: Entrypoint) => void) {\n if (this.#supersededWith) {\n callback(this.#supersededWith);\n return () => {};\n }\n\n this.onSupersedeHandlers.push(callback);\n\n return () => {\n const index = this.onSupersedeHandlers.indexOf(callback);\n if (index >= 0) {\n this.onSupersedeHandlers.splice(index, 1);\n }\n };\n }\n\n public setTransformResult(res: ITransformFileResult | null) {\n this.#hasLinariaMetadata = Boolean(res?.metadata);\n this.#transformResultCode = res?.code ?? null;\n\n this.services.eventEmitter.entrypointEvent(this.seqId, {\n isNull: res === null,\n type: 'setTransformResult',\n });\n }\n\n private supersede(newOnlyOrEntrypoint: string[] | Entrypoint): Entrypoint {\n const newEntrypoint =\n newOnlyOrEntrypoint instanceof Entrypoint\n ? newOnlyOrEntrypoint\n : new Entrypoint(\n this.services,\n this.parents,\n this.initialCode,\n this.name,\n newOnlyOrEntrypoint,\n this.exports,\n this.evaluatedOnly,\n this.loadedAndParsed,\n this.resolveTasks,\n this.dependencies,\n this.generation + 1\n );\n\n this.services.eventEmitter.entrypointEvent(this.seqId, {\n type: 'superseded',\n with: newEntrypoint.seqId,\n });\n this.log(\n 'superseded by %s (%o -> %o)',\n newEntrypoint.name,\n this.only,\n newEntrypoint.only\n );\n this.#supersededWith = newEntrypoint;\n this.on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B,CAAC,CAAC;IACF,IAAI,CAACnB,GAAG,CACN,6BAA6B,EAC7B+B,aAAa,CAACzD,IAAI,EAClB,IAAI,CAACkB,IAAI,EACTuC,aAAa,CAACvC,IAChB,CAAC;IACD,IAAI,CAAC,CAACL,cAAc,GAAG4C,aAAa;IACpC,IAAI,CAAChD,mBAAmB,CAACqF,OAAO,CAAEC,OAAO,IAAKA,OAAO,CAACtC,aAAa,CAAC,CAAC;IAErE,OAAOA,aAAa;EACtB;AACF"}
1
+ {"version":3,"file":"Entrypoint.js","names":["invariant","BaseEntrypoint","isSuperSet","mergeOnly","EvaluatedEntrypoint","AbortError","BaseAction","UnprocessedEntrypointError","EMPTY_FILE","hasLoop","name","parent","processed","includes","p","parents","found","Entrypoint","evaluated","onSupersedeHandlers","actionsCache","Map","hasWywMetadata","supersededWith","transformResultCode","constructor","services","initialCode","only","exports","evaluatedOnly","loadedAndParsed","resolveTasks","dependencies","generation","loadAndParseFn","log","code","undefined","cache","invalidateIfChanged","extend","originalCode","ignored","evaluator","transformedCode","createRoot","loadedCode","created","create","eventEmitter","perf","status","entrypoint","innerCreate","seqId","add","cached","get","changed","mergedOnly","filter","i","isLoop","map","push","supersede","newEntrypoint","addDependency","dependency","delete","source","set","addResolveTask","assertNotSuperseded","assertTransformed","createAction","actionType","data","abortSignal","has","aborted","newAction","entrypointEvent","type","actionIdx","idx","createChild","createEvaluated","exportsProxy","getDependency","getResolveTask","onSupersede","callback","index","indexOf","splice","setTransformResult","res","Boolean","metadata","isNull","newOnlyOrEntrypoint","with","forEach","handler"],"sources":["../../src/transform/Entrypoint.ts"],"sourcesContent":["import { invariant } from 'ts-invariant';\n\nimport type { ParentEntrypoint, ITransformFileResult } from '../types';\n\nimport { BaseEntrypoint } from './BaseEntrypoint';\nimport { isSuperSet, mergeOnly } from './Entrypoint.helpers';\nimport type {\n IEntrypointCode,\n IEntrypointDependency,\n IIgnoredEntrypoint,\n} from './Entrypoint.types';\nimport { EvaluatedEntrypoint } from './EvaluatedEntrypoint';\nimport { AbortError } from './actions/AbortError';\nimport type { ActionByType } from './actions/BaseAction';\nimport { BaseAction } from './actions/BaseAction';\nimport { UnprocessedEntrypointError } from './actions/UnprocessedEntrypointError';\nimport type { Services, ActionTypes, ActionQueueItem } from './types';\n\nconst EMPTY_FILE = '=== empty file ===';\n\nfunction hasLoop(\n name: string,\n parent: ParentEntrypoint,\n processed: string[] = []\n): boolean {\n if (parent.name === name || processed.includes(parent.name)) {\n return true;\n }\n\n for (const p of parent.parents) {\n const found = hasLoop(name, p, [...processed, parent.name]);\n if (found) {\n return found;\n }\n }\n\n return false;\n}\n\nexport class Entrypoint extends BaseEntrypoint {\n public readonly evaluated = false;\n\n public readonly loadedAndParsed: IEntrypointCode | IIgnoredEntrypoint;\n\n protected onSupersedeHandlers: Array<(newEntrypoint: Entrypoint) => void> =\n [];\n\n private actionsCache: Map<\n ActionTypes,\n Map<unknown, BaseAction<ActionQueueItem>>\n > = new Map();\n\n #hasWywMetadata: boolean = false;\n\n #supersededWith: Entrypoint | null = null;\n\n #transformResultCode: string | null = null;\n\n private constructor(\n services: Services,\n parents: ParentEntrypoint[],\n public readonly initialCode: string | undefined,\n name: string,\n only: string[],\n exports: Record<string | symbol, unknown> | undefined,\n evaluatedOnly: string[],\n loadedAndParsed?: IEntrypointCode | IIgnoredEntrypoint,\n protected readonly resolveTasks = new Map<\n string,\n Promise<IEntrypointDependency>\n >(),\n protected readonly dependencies = new Map<string, IEntrypointDependency>(),\n generation = 1\n ) {\n super(services, evaluatedOnly, exports, generation, name, only, parents);\n\n this.loadedAndParsed =\n loadedAndParsed ??\n services.loadAndParseFn(\n services,\n name,\n initialCode,\n parents[0]?.log ?? services.log\n );\n\n if (this.loadedAndParsed.code !== undefined) {\n services.cache.invalidateIfChanged(name, this.loadedAndParsed.code);\n }\n\n this.log.extend('source')(\n 'created %s (%o)\\n%s',\n name,\n only,\n this.originalCode || EMPTY_FILE\n );\n }\n\n public get ignored() {\n return this.loadedAndParsed.evaluator === 'ignored';\n }\n\n public get originalCode() {\n return this.loadedAndParsed.code;\n }\n\n public get supersededWith(): Entrypoint | null {\n return this.#supersededWith?.supersededWith ?? this.#supersededWith;\n }\n\n public get transformedCode(): string | null {\n return (\n this.#transformResultCode ?? this.supersededWith?.transformedCode ?? null\n );\n }\n\n public static createRoot(\n services: Services,\n name: string,\n only: string[],\n loadedCode: string | undefined\n ): Entrypoint {\n const created = Entrypoint.create(services, null, name, only, loadedCode);\n invariant(created !== 'loop', 'loop detected');\n\n return created;\n }\n\n /**\n * Creates an entrypoint for the specified file.\n * If there is already an entrypoint for this file, there will be four possible outcomes:\n * 1. If `loadedCode` is specified and is different from the one that was used to create the existing entrypoint,\n * the existing entrypoint will be superseded by a new one and all cached results for it will be invalidated.\n * It can happen if the file was changed and the watcher notified us about it, or we received a new version\n * of the file from a loader whereas the previous one was loaded from the filesystem.\n * The new entrypoint will be returned.\n * 2. If `only` is subset of the existing entrypoint's `only`, the existing entrypoint will be returned.\n * 3. If `only` is superset of the existing entrypoint's `only`, the existing entrypoint will be superseded and the new one will be returned.\n * 4. If a loop is detected, 'ignored' will be returned, the existing entrypoint will be superseded or not depending on the `only` value.\n */\n protected static create(\n services: Services,\n parent: ParentEntrypoint | null,\n name: string,\n only: string[],\n loadedCode: string | undefined\n ): Entrypoint | 'loop' {\n const { cache, eventEmitter } = services;\n return eventEmitter.perf('createEntrypoint', () => {\n const [status, entrypoint] = Entrypoint.innerCreate(\n services,\n parent\n ? {\n evaluated: parent.evaluated,\n log: parent.log,\n name: parent.name,\n parents: parent.parents,\n seqId: parent.seqId,\n }\n : null,\n name,\n only,\n loadedCode\n );\n\n if (status !== 'cached') {\n cache.add('entrypoints', name, entrypoint);\n }\n\n return status === 'loop' ? 'loop' : entrypoint;\n });\n }\n\n private static innerCreate(\n services: Services,\n parent: ParentEntrypoint | null,\n name: string,\n only: string[],\n loadedCode: string | undefined\n ): ['loop' | 'created' | 'cached', Entrypoint] {\n const { cache } = services;\n\n const cached = cache.get('entrypoints', name);\n const changed =\n loadedCode !== undefined\n ? cache.invalidateIfChanged(name, loadedCode)\n : false;\n\n if (!cached?.evaluated && cached?.ignored) {\n return ['cached', cached];\n }\n\n const exports = cached?.exports;\n const evaluatedOnly = cached?.evaluatedOnly ?? [];\n const mergedOnly =\n !changed && cached?.only\n ? mergeOnly(cached.only, only).filter((i) => !evaluatedOnly.includes(i))\n : only;\n\n if (cached?.evaluated) {\n cached.log('is already evaluated with', cached.evaluatedOnly);\n }\n\n if (!changed && cached && !cached.evaluated) {\n const isLoop = parent && hasLoop(name, parent);\n if (isLoop) {\n parent.log('[createEntrypoint] %s is a loop', name);\n }\n\n if (parent && !cached.parents.map((p) => p.name).includes(parent.name)) {\n cached.parents.push(parent);\n }\n\n if (isSuperSet(cached.only, mergedOnly)) {\n cached.log('is cached', name);\n return [isLoop ? 'loop' : 'cached', cached];\n }\n\n cached.log(\n 'is cached, but with different `only` %o (the cached one %o)',\n only,\n cached?.only\n );\n\n return [isLoop ? 'loop' : 'created', cached.supersede(mergedOnly)];\n }\n\n const newEntrypoint = new Entrypoint(\n services,\n parent ? [parent] : [],\n loadedCode,\n name,\n mergedOnly,\n exports,\n evaluatedOnly,\n undefined,\n cached && 'resolveTasks' in cached ? cached.resolveTasks : undefined,\n cached && 'dependencies' in cached ? cached.dependencies : undefined,\n cached ? cached.generation + 1 : 1\n );\n\n if (cached && !cached.evaluated) {\n cached.log('is cached, but with different code');\n cached.supersede(newEntrypoint);\n }\n\n return ['created', newEntrypoint];\n }\n\n public addDependency(dependency: IEntrypointDependency): void {\n this.resolveTasks.delete(dependency.source);\n this.dependencies.set(dependency.source, dependency);\n }\n\n public addResolveTask(\n name: string,\n dependency: Promise<IEntrypointDependency>\n ): void {\n this.resolveTasks.set(name, dependency);\n }\n\n public assertNotSuperseded() {\n if (this.supersededWith) {\n this.log('superseded');\n throw new AbortError('superseded');\n }\n }\n\n public assertTransformed() {\n if (this.transformedCode === null) {\n this.log('not transformed');\n throw new UnprocessedEntrypointError(this.supersededWith ?? this);\n }\n }\n\n public createAction<\n TType extends ActionTypes,\n TAction extends ActionByType<TType>,\n >(\n actionType: TType,\n data: TAction['data'],\n abortSignal: AbortSignal | null = null\n ): BaseAction<TAction> {\n if (!this.actionsCache.has(actionType)) {\n this.actionsCache.set(actionType, new Map());\n }\n\n const cache = this.actionsCache.get(actionType)!;\n const cached = cache.get(data);\n if (cached && !cached.abortSignal?.aborted) {\n return cached as BaseAction<TAction>;\n }\n\n const newAction = new BaseAction<TAction>(\n actionType as TAction['type'],\n this.services,\n this,\n data,\n abortSignal\n );\n\n cache.set(data, newAction);\n\n this.services.eventEmitter.entrypointEvent(this.seqId, {\n type: 'actionCreated',\n actionType,\n actionIdx: newAction.idx,\n });\n\n return newAction;\n }\n\n public createChild(\n name: string,\n only: string[],\n loadedCode?: string\n ): Entrypoint | 'loop' {\n return Entrypoint.create(this.services, this, name, only, loadedCode);\n }\n\n public createEvaluated() {\n const evaluatedOnly = mergeOnly(this.evaluatedOnly, this.only);\n this.log('create EvaluatedEntrypoint for %o', evaluatedOnly);\n\n return new EvaluatedEntrypoint(\n this.services,\n evaluatedOnly,\n this.exportsProxy,\n this.generation + 1,\n this.name,\n this.only,\n this.parents\n );\n }\n\n public getDependency(name: string): IEntrypointDependency | undefined {\n return this.dependencies.get(name);\n }\n\n public getResolveTask(\n name: string\n ): Promise<IEntrypointDependency> | undefined {\n return this.resolveTasks.get(name);\n }\n\n public hasWywMetadata() {\n return this.#hasWywMetadata;\n }\n\n public onSupersede(callback: (newEntrypoint: Entrypoint) => void) {\n if (this.#supersededWith) {\n callback(this.#supersededWith);\n return () => {};\n }\n\n this.onSupersedeHandlers.push(callback);\n\n return () => {\n const index = this.onSupersedeHandlers.indexOf(callback);\n if (index >= 0) {\n this.onSupersedeHandlers.splice(index, 1);\n }\n };\n }\n\n public setTransformResult(res: ITransformFileResult | null) {\n this.#hasWywMetadata = Boolean(res?.metadata);\n this.#transformResultCode = res?.code ?? null;\n\n this.services.eventEmitter.entrypointEvent(this.seqId, {\n isNull: res === null,\n type: 'setTransformResult',\n });\n }\n\n private supersede(newOnlyOrEntrypoint: string[] | Entrypoint): Entrypoint {\n const newEntrypoint =\n newOnlyOrEntrypoint instanceof Entrypoint\n ? newOnlyOrEntrypoint\n : new Entrypoint(\n this.services,\n this.parents,\n this.initialCode,\n this.name,\n newOnlyOrEntrypoint,\n this.exports,\n this.evaluatedOnly,\n this.loadedAndParsed,\n this.resolveTasks,\n this.dependencies,\n this.generation + 1\n );\n\n this.services.eventEmitter.entrypointEvent(this.seqId, {\n type: 'superseded',\n with: newEntrypoint.seqId,\n });\n this.log(\n 'superseded by %s (%o -> %o)',\n newEntrypoint.name,\n this.only,\n newEntrypoint.only\n );\n this.#supersededWith = newEntrypoint;\n this.onSupersedeHandlers.forEach((handler) => handler(newEntrypoint));\n\n return newEntrypoint;\n }\n}\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,cAAc;AAIxC,SAASC,cAAc,QAAQ,kBAAkB;AACjD,SAASC,UAAU,EAAEC,SAAS,QAAQ,sBAAsB;AAM5D,SAASC,mBAAmB,QAAQ,uBAAuB;AAC3D,SAASC,UAAU,QAAQ,sBAAsB;AAEjD,SAASC,UAAU,QAAQ,sBAAsB;AACjD,SAASC,0BAA0B,QAAQ,sCAAsC;AAGjF,MAAMC,UAAU,GAAG,oBAAoB;AAEvC,SAASC,OAAOA,CACdC,IAAY,EACZC,MAAwB,EACxBC,SAAmB,GAAG,EAAE,EACf;EACT,IAAID,MAAM,CAACD,IAAI,KAAKA,IAAI,IAAIE,SAAS,CAACC,QAAQ,CAACF,MAAM,CAACD,IAAI,CAAC,EAAE;IAC3D,OAAO,IAAI;EACb;EAEA,KAAK,MAAMI,CAAC,IAAIH,MAAM,CAACI,OAAO,EAAE;IAC9B,MAAMC,KAAK,GAAGP,OAAO,CAACC,IAAI,EAAEI,CAAC,EAAE,CAAC,GAAGF,SAAS,EAAED,MAAM,CAACD,IAAI,CAAC,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BAAmB,YAAYrF,UAAU,GACrCqF,mBAAmB,GACnB,IAAIrF,UAAU,CACZ,IAAI,CAACS,QAAQ,EACb,IAAI,CAACX,OAAO,EACZ,IAAI,CAACY,WAAW,EAChB,IAAI,CAACjB,IAAI,EACT4F,mBAAmB,EACnB,IAAI,CAACzE,OAAO,EACZ,IAAI,CAACC,aAAa,EAClB,IAAI,CAACC,eAAe,EACpB,IAAI,CAACC,YAAY,EACjB,IAAI,CAACC,YAAY,EACjB,IAAI,CAACC,UAAU,GAAG,CACpB,CAAC;IAEP,IAAI,CAACR,QAAQ,CAACwB,YAAY,CAACiC,eAAe,CAAC,IAAI,CAAC5B,KAAK,EAAE;MACrD6B,IAAI,EAAE,YAAY;MAClBmB,IAAI,EAAEpC,aAAa,CAACZ;IACtB,CAAC,CAAC;IACF,IAAI,CAACnB,GAAG,CACN,6BAA6B,EAC7B+B,aAAa,CAACzD,IAAI,EAClB,IAAI,CAACkB,IAAI,EACTuC,aAAa,CAACvC,IAChB,CAAC;IACD,IAAI,CAAC,CAACL,cAAc,GAAG4C,aAAa;IACpC,IAAI,CAAChD,mBAAmB,CAACqF,OAAO,CAAEC,OAAO,IAAKA,OAAO,CAACtC,aAAa,CAAC,CAAC;IAErE,OAAOA,aAAa;EACtB;AACF"}
@@ -4,7 +4,8 @@ import { getTransformMetadata } from '../../utils/TransformMetadata';
4
4
  /**
5
5
  * Parses the specified file, finds tags, applies run-time replacements,
6
6
  * removes dead code.
7
- */ // eslint-disable-next-line require-yield
7
+ */
8
+ // eslint-disable-next-line require-yield
8
9
  export function* collect() {
9
10
  const {
10
11
  babel,
@@ -28,7 +29,7 @@ export function* collect() {
28
29
  values: valueCache
29
30
  }]];
30
31
  const transformConfig = buildOptions({
31
- envName: 'linaria',
32
+ envName: 'wyw-in-js',
32
33
  plugins: transformPlugins,
33
34
  sourceMaps: true,
34
35
  sourceFileName: name,
@@ -1 +1 @@
1
- {"version":3,"file":"collect.js","names":["buildOptions","filename","collectorPlugin","getTransformMetadata","collect","babel","options","services","valueCache","data","entrypoint","loadedAndParsed","name","evaluator","Error","transformPlugins","pluginOptions","values","transformConfig","envName","plugins","sourceMaps","sourceFileName","inputSourceMap","root","ast","babelrc","configFile","sourceType","result","transformFromAstSync","code","cwd","program","transformMetadata","metadata","map"],"sources":["../../../src/transform/generators/collect.ts"],"sourcesContent":["import type { PluginItem } from '@babel/core';\n\nimport { buildOptions } from '../../options/buildOptions';\nimport { filename as collectorPlugin } from '../../plugins/collector';\nimport { getTransformMetadata } from '../../utils/TransformMetadata';\nimport type { ICollectAction, SyncScenarioForAction } from '../types';\n\n/**\n * Parses the specified file, finds tags, applies run-time replacements,\n * removes dead code.\n */\n// eslint-disable-next-line require-yield\nexport function* collect(\n this: ICollectAction\n): SyncScenarioForAction<ICollectAction> {\n const { babel, options } = this.services;\n const { valueCache } = this.data;\n const { entrypoint } = this;\n const { loadedAndParsed, name } = entrypoint;\n\n if (loadedAndParsed.evaluator === 'ignored') {\n throw new Error('entrypoint was ignored');\n }\n\n const transformPlugins: PluginItem[] = [\n [\n collectorPlugin,\n {\n ...options.pluginOptions,\n values: valueCache,\n },\n ],\n ];\n\n const transformConfig = buildOptions({\n envName: 'linaria',\n plugins: transformPlugins,\n sourceMaps: true,\n sourceFileName: name,\n inputSourceMap: options.inputSourceMap,\n root: options.root,\n ast: true,\n babelrc: false,\n configFile: false,\n sourceType: 'unambiguous',\n });\n\n const result = babel.transformFromAstSync(\n loadedAndParsed.ast,\n loadedAndParsed.code,\n {\n ...transformConfig,\n cwd: options.root,\n filename: name,\n }\n );\n\n if (!result || !result.ast?.program) {\n throw new Error('Babel transform failed');\n }\n\n const transformMetadata = getTransformMetadata(result.metadata);\n\n return {\n ast: result.ast,\n code: result.code,\n map: result.map,\n metadata: transformMetadata ?? null,\n };\n}\n"],"mappings":"AAEA,SAASA,YAAY,QAAQ,4BAA4B;AACzD,SAASC,QAAQ,IAAIC,eAAe,QAAQ,yBAAyB;AACrE,SAASC,oBAAoB,QA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,GAAG/B,oBAAoB,CAAC0B,MAAM,CAACM,QAAQ,CAAC;EAE/D,OAAO;IACLV,GAAG,EAAEI,MAAM,CAACJ,GAAG;IACfM,IAAI,EAAEF,MAAM,CAACE,IAAI;IACjBK,GAAG,EAAEP,MAAM,CAACO,GAAG;IACfD,QAAQ,EAAED,iBAAiB,IAAI;EACjC,CAAC;AACH"}
1
+ {"version":3,"file":"collect.js","names":["buildOptions","filename","collectorPlugin","getTransformMetadata","collect","babel","options","services","valueCache","data","entrypoint","loadedAndParsed","name","evaluator","Error","transformPlugins","pluginOptions","values","transformConfig","envName","plugins","sourceMaps","sourceFileName","inputSourceMap","root","ast","babelrc","configFile","sourceType","result","transformFromAstSync","code","cwd","program","transformMetadata","metadata","map"],"sources":["../../../src/transform/generators/collect.ts"],"sourcesContent":["import type { PluginItem } from '@babel/core';\n\nimport { buildOptions } from '../../options/buildOptions';\nimport { filename as collectorPlugin } from '../../plugins/collector';\nimport { getTransformMetadata } from '../../utils/TransformMetadata';\nimport type { ICollectAction, SyncScenarioForAction } from '../types';\n\n/**\n * Parses the specified file, finds tags, applies run-time replacements,\n * removes dead code.\n */\n// eslint-disable-next-line require-yield\nexport function* collect(\n this: ICollectAction\n): SyncScenarioForAction<ICollectAction> {\n const { babel, options } = this.services;\n const { valueCache } = this.data;\n const { entrypoint } = this;\n const { loadedAndParsed, name } = entrypoint;\n\n if (loadedAndParsed.evaluator === 'ignored') {\n throw new Error('entrypoint was ignored');\n }\n\n const transformPlugins: PluginItem[] = [\n [\n collectorPlugin,\n {\n ...options.pluginOptions,\n values: valueCache,\n },\n ],\n ];\n\n const transformConfig = buildOptions({\n envName: 'wyw-in-js',\n plugins: transformPlugins,\n sourceMaps: true,\n sourceFileName: name,\n inputSourceMap: options.inputSourceMap,\n root: options.root,\n ast: true,\n babelrc: false,\n configFile: false,\n sourceType: 'unambiguous',\n });\n\n const result = babel.transformFromAstSync(\n loadedAndParsed.ast,\n loadedAndParsed.code,\n {\n ...transformConfig,\n cwd: options.root,\n filename: name,\n }\n );\n\n if (!result || !result.ast?.program) {\n throw new Error('Babel transform failed');\n }\n\n const transformMetadata = getTransformMetadata(result.metadata);\n\n return {\n ast: result.ast,\n code: result.code,\n map: result.map,\n metadata: transformMetadata ?? null,\n };\n}\n"],"mappings":"AAEA,SAASA,YAAY,QAAQ,4BAA4B;AACzD,SAASC,QAAQ,IAAIC,eAAe,QAAQ,yBAAyB;AACrE,SAASC,oBAAoB,QAAQ,+BAA+B;AAGpE;AACA;AACA;AACA;AACA;AACA,OAAO,UAAUC,OAAOA,CAAA,EAEiB;EACvC,MAAM;IAAEC,KAAK;IAAEC;EAAQ,CAAC,GAAG,IAAI,CAACC,QAAQ;EACxC,MAAM;IAAEC;EAAW,CAAC,GAAG,IAAI,CAACC,IAAI;EAChC,MAAM;IAAEC;EAAW,CAAC,GAAG,IAAI;EAC3B,MAAM;IAAEC,eAAe;IAAEC;EAAK,CAAC,GAAGF,UAAU;EAE5C,IAAIC,eAAe,CAACE,SAAS,KAAK,SAAS,EAAE;IAC3C,MAAM,IAAIC,KAAK,CAAC,wBAAwB,CAAC;EAC3C;EAEA,MAAMC,gBAA8B,GAAG,CACrC,CACEb,eAAe,EACf;IACE,GAAGI,OAAO,CAACU,aAAa;IACxBC,MAAM,EAAET;EACV,CAAC,CACF,CACF;EAED,MAAMU,eAAe,GAAGlB,YAAY,CAAC;IACnCmB,OAAO,EAAE,WAAW;IACpBC,OAAO,EAAEL,gBAAgB;IACzBM,UAAU,EAAE,IAAI;IAChBC,cAAc,EAAEV,IAAI;IACpBW,cAAc,EAAEjB,OAAO,CAACiB,cAAc;IACtCC,IAAI,EAAElB,OAAO,CAACkB,IAAI;IAClBC,GAAG,EAAE,IAAI;IACTC,OAAO,EAAE,KAAK;IACdC,UAAU,EAAE,KAAK;IACjBC,UAAU,EAAE;EACd,CAAC,CAAC;EAEF,MAAMC,MAAM,GAAGxB,KAAK,CAACyB,oBAAoB,CACvCnB,eAAe,CAACc,GAAG,EACnBd,eAAe,CAACoB,IAAI,EACpB;IACE,GAAGb,eAAe;IAClBc,GAAG,EAAE1B,OAAO,CAACkB,IAAI;IACjBvB,QAAQ,EAAEW;EACZ,CACF,CAAC;EAED,IAAI,CAACiB,MAAM,IAAI,CAACA,MAAM,CAACJ,GAAG,EAAEQ,OAAO,EAAE;IACnC,MAAM,IAAInB,KAAK,CAAC,wBAAwB,CAAC;EAC3C;EAEA,MAAMoB,iBAAiB,GAAG/B,oBAAoB,CAAC0B,MAAM,CAACM,QAAQ,CAAC;EAE/D,OAAO;IACLV,GAAG,EAAEI,MAAM,CAACJ,GAAG;IACfM,IAAI,EAAEF,MAAM,CAACE,IAAI;IACjBK,GAAG,EAAEP,MAAM,CAACO,GAAG;IACfD,QAAQ,EAAED,iBAAiB,IAAI;EACjC,CAAC;AACH"}
@@ -1,5 +1,5 @@
1
1
  import evaluate from '../../evaluators';
2
- import hasLinariaPreval from '../../utils/hasLinariaPreval';
2
+ import hasWywPreval from '../../utils/hasWywPreval';
3
3
  import { isUnprocessedEntrypointError } from '../actions/UnprocessedEntrypointError';
4
4
  const wrap = fn => {
5
5
  try {
@@ -21,7 +21,7 @@ export function* evalFile() {
21
21
  const {
22
22
  log
23
23
  } = entrypoint;
24
- log(`>> evaluate __linariaPreval`);
24
+ log(`>> evaluate __wywPreval`);
25
25
  let evaluated;
26
26
  while (evaluated === undefined) {
27
27
  try {
@@ -35,16 +35,16 @@ export function* evalFile() {
35
35
  }
36
36
  }
37
37
  }
38
- const linariaPreval = hasLinariaPreval(evaluated.value) ? evaluated.value.__linariaPreval : undefined;
39
- if (!linariaPreval) {
38
+ const wywPreval = hasWywPreval(evaluated.value) ? evaluated.value.__wywPreval : undefined;
39
+ if (!wywPreval) {
40
40
  return null;
41
41
  }
42
42
  const valueCache = new Map();
43
- Object.entries(linariaPreval).forEach(([key, lazyValue]) => {
43
+ Object.entries(wywPreval).forEach(([key, lazyValue]) => {
44
44
  const value = wrap(lazyValue);
45
45
  valueCache.set(key, value);
46
46
  });
47
- log(`<< evaluated __linariaPreval %O`, valueCache);
47
+ log(`<< evaluated __wywPreval %O`, valueCache);
48
48
  return [valueCache, evaluated.dependencies];
49
49
  }
50
50
  //# sourceMappingURL=evalFile.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"evalFile.js","names":["evaluate","hasLinariaPreval","isUnprocessedEntrypointError","wrap","fn","e","evalFile","entrypoint","log","evaluated","undefined","services","linariaPreval","value","__linariaPreval","valueCache","Map","Object","entries","forEach","key","lazyValue","set","dependencies"],"sources":["../../../src/transform/generators/evalFile.ts"],"sourcesContent":["import type { ValueCache } from '@wyw-in-js/processor-utils';\n\nimport type { IEvaluateResult } from '../../evaluators';\nimport evaluate from '../../evaluators';\nimport hasLinariaPreval from '../../utils/hasLinariaPreval';\nimport { isUnprocessedEntrypointError } from '../actions/UnprocessedEntrypointError';\nimport type { IEvalAction, SyncScenarioForAction } from '../types';\n\nconst wrap = <T>(fn: () => T): T | Error => {\n try {\n return fn();\n } catch (e) {\n return e as Error;\n }\n};\n\n/**\n * Executes the code prepared in previous steps within the current `Entrypoint`.\n * Returns all exports that were requested in `only`.\n */\n// eslint-disable-next-line require-yield\nexport function* evalFile(\n this: IEvalAction\n): SyncScenarioForAction<IEvalAction> {\n const { entrypoint } = this;\n const { log } = entrypoint;\n\n log(`>> evaluate __linariaPreval`);\n\n let evaluated: IEvaluateResult | undefined;\n\n while (evaluated === undefined) {\n try {\n evaluated = evaluate(this.services, entrypoint);\n } catch (e) {\n if (isUnprocessedEntrypointError(e)) {\n entrypoint.log(\n 'Evaluation has been aborted because one if the required files is not processed. Schedule reprocessing and repeat evaluation.'\n );\n yield ['processEntrypoint', e.entrypoint, undefined];\n } else {\n throw e;\n }\n }\n }\n\n const linariaPreval = hasLinariaPreval(evaluated.value)\n ? evaluated.value.__linariaPreval\n : undefined;\n\n if (!linariaPreval) {\n return null;\n }\n\n const valueCache: ValueCache = new Map();\n Object.entries(linariaPreval).forEach(([key, lazyValue]) => {\n const value = wrap(lazyValue);\n valueCache.set(key, value);\n });\n\n log(`<< evaluated __linariaPreval %O`, valueCache);\n\n return [valueCache, evaluated.dependencies];\n}\n"],"mappings":"AAGA,OAAOA,QAAQ,MAAM,kBAAkB;AACvC,OAAOC,gBAAgB,MAAM,8BAA8B;AAC3D,SAASC,4BAA4B,QAAQ,uCAAuC;AAGpF,MAAMC,IAAI,GAAOC,EAAW,IAAgB;EAC1C,IAAI;IACF,OAAOA,EAAE,CAAC,CAAC;EACb,CAAC,CAAC,OAAOC,CAAC,EAAE;IACV,OAAOA,CAAC;EACV;AACF,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA,OAAO,UAAUC,QAAQA,CAAA,EAEa;EACpC,MAAM;IAAEC;EAAW,CAAC,GAAG,IAAI;EAC3B,MAAM;IAAEC;EAAI,CAAC,GAAGD,UAAU;EAE1BC,GAAG,CAAE,6BAA4B,CAAC;EAElC,IAAIC,SAAsC;EAE1C,OAAOA,SAAS,KAAKC,SAAS,EAAE;IAC9B,IAAI;MACFD,SAAS,GAAGT,QAAQ,CAAC,IAAI,CAACW,QAAQ,EAAEJ,UAAU,CAAC;IACjD,CAAC,CAAC,OAAOF,CAAC,EAAE;MACV,IAAIH,4BAA4B,CAACG,CAAC,CAAC,EAAE;QACnCE,UAAU,CAACC,GAAG,CACZ,8HACF,CAAC;QACD,MAAM,CAAC,mBAAmB,EAAEH,CAAC,CAACE,UAAU,EAAEG,SAAS,CAAC;MACtD,CAAC,MAAM;QACL,MAAML,CAAC;MACT;IACF;EACF;EAEA,MAAMO,aAAa,GAAGX,gBAAgB,CAACQ,SAAS,CAACI,KAAK,CAAC,GACnDJ,SAAS,CAACI,KAAK,CAACC,eAAe,GAC/BJ,SAAS;EAEb,IAAI,CAACE,aAAa,EAAE;IAClB,OAAO,IAAI;EACb;EAEA,MAAMG,UAAsB,GAAG,IAAIC,GAAG,CAAC,CAAC;EACxCC,MAAM,CAACC,OAAO,CAACN,aAAa,CAAC,CAACO,OAAO,CAAC,CAAC,CAACC,GAAG,EAAEC,SAAS,CAAC,KAAK;IAC1D,MAAMR,KAAK,GAAGV,IAAI,CAACkB,SAAS,CAAC;IAC7BN,UAAU,CAACO,GAAG,CAACF,GAAG,EAAEP,KAAK,CAAC;EAC5B,CAAC,CAAC;EAEFL,GAAG,CAAE,iCAAgC,EAAEO,UAAU,CAAC;EAElD,OAAO,CAACA,UAAU,EAAEN,SAAS,CAACc,YAAY,CAAC;AAC7C"}
1
+ {"version":3,"file":"evalFile.js","names":["evaluate","hasWywPreval","isUnprocessedEntrypointError","wrap","fn","e","evalFile","entrypoint","log","evaluated","undefined","services","wywPreval","value","__wywPreval","valueCache","Map","Object","entries","forEach","key","lazyValue","set","dependencies"],"sources":["../../../src/transform/generators/evalFile.ts"],"sourcesContent":["import type { ValueCache } from '@wyw-in-js/processor-utils';\n\nimport type { IEvaluateResult } from '../../evaluators';\nimport evaluate from '../../evaluators';\nimport hasWywPreval from '../../utils/hasWywPreval';\nimport { isUnprocessedEntrypointError } from '../actions/UnprocessedEntrypointError';\nimport type { IEvalAction, SyncScenarioForAction } from '../types';\n\nconst wrap = <T>(fn: () => T): T | Error => {\n try {\n return fn();\n } catch (e) {\n return e as Error;\n }\n};\n\n/**\n * Executes the code prepared in previous steps within the current `Entrypoint`.\n * Returns all exports that were requested in `only`.\n */\n// eslint-disable-next-line require-yield\nexport function* evalFile(\n this: IEvalAction\n): SyncScenarioForAction<IEvalAction> {\n const { entrypoint } = this;\n const { log } = entrypoint;\n\n log(`>> evaluate __wywPreval`);\n\n let evaluated: IEvaluateResult | undefined;\n\n while (evaluated === undefined) {\n try {\n evaluated = evaluate(this.services, entrypoint);\n } catch (e) {\n if (isUnprocessedEntrypointError(e)) {\n entrypoint.log(\n 'Evaluation has been aborted because one if the required files is not processed. Schedule reprocessing and repeat evaluation.'\n );\n yield ['processEntrypoint', e.entrypoint, undefined];\n } else {\n throw e;\n }\n }\n }\n\n const wywPreval = hasWywPreval(evaluated.value)\n ? evaluated.value.__wywPreval\n : undefined;\n\n if (!wywPreval) {\n return null;\n }\n\n const valueCache: ValueCache = new Map();\n Object.entries(wywPreval).forEach(([key, lazyValue]) => {\n const value = wrap(lazyValue);\n valueCache.set(key, value);\n });\n\n log(`<< evaluated __wywPreval %O`, valueCache);\n\n return [valueCache, evaluated.dependencies];\n}\n"],"mappings":"AAGA,OAAOA,QAAQ,MAAM,kBAAkB;AACvC,OAAOC,YAAY,MAAM,0BAA0B;AACnD,SAASC,4BAA4B,QAAQ,uCAAuC;AAGpF,MAAMC,IAAI,GAAOC,EAAW,IAAgB;EAC1C,IAAI;IACF,OAAOA,EAAE,CAAC,CAAC;EACb,CAAC,CAAC,OAAOC,CAAC,EAAE;IACV,OAAOA,CAAC;EACV;AACF,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA,OAAO,UAAUC,QAAQA,CAAA,EAEa;EACpC,MAAM;IAAEC;EAAW,CAAC,GAAG,IAAI;EAC3B,MAAM;IAAEC;EAAI,CAAC,GAAGD,UAAU;EAE1BC,GAAG,CAAE,yBAAwB,CAAC;EAE9B,IAAIC,SAAsC;EAE1C,OAAOA,SAAS,KAAKC,SAAS,EAAE;IAC9B,IAAI;MACFD,SAAS,GAAGT,QAAQ,CAAC,IAAI,CAACW,QAAQ,EAAEJ,UAAU,CAAC;IACjD,CAAC,CAAC,OAAOF,CAAC,EAAE;MACV,IAAIH,4BAA4B,CAACG,CAAC,CAAC,EAAE;QACnCE,UAAU,CAACC,GAAG,CACZ,8HACF,CAAC;QACD,MAAM,CAAC,mBAAmB,EAAEH,CAAC,CAACE,UAAU,EAAEG,SAAS,CAAC;MACtD,CAAC,MAAM;QACL,MAAML,CAAC;MACT;IACF;EACF;EAEA,MAAMO,SAAS,GAAGX,YAAY,CAACQ,SAAS,CAACI,KAAK,CAAC,GAC3CJ,SAAS,CAACI,KAAK,CAACC,WAAW,GAC3BJ,SAAS;EAEb,IAAI,CAACE,SAAS,EAAE;IACd,OAAO,IAAI;EACb;EAEA,MAAMG,UAAsB,GAAG,IAAIC,GAAG,CAAC,CAAC;EACxCC,MAAM,CAACC,OAAO,CAACN,SAAS,CAAC,CAACO,OAAO,CAAC,CAAC,CAACC,GAAG,EAAEC,SAAS,CAAC,KAAK;IACtD,MAAMR,KAAK,GAAGV,IAAI,CAACkB,SAAS,CAAC;IAC7BN,UAAU,CAACO,GAAG,CAACF,GAAG,EAAEP,KAAK,CAAC;EAC5B,CAAC,CAAC;EAEFL,GAAG,CAAE,6BAA4B,EAAEO,UAAU,CAAC;EAE9C,OAAO,CAACA,UAAU,EAAEN,SAAS,CAACc,YAAY,CAAC;AAC7C"}
@@ -1,7 +1,6 @@
1
1
  import path from 'path';
2
2
  import { SourceMapGenerator } from 'source-map';
3
- import stylis from 'stylis';
4
- const STYLIS_DECLARATION = 1;
3
+ import { compile, serialize, stringify, middleware, prefixer, namespace } from 'stylis';
5
4
  const posixSep = path.posix.sep;
6
5
  export function transformUrl(url, outputFilename, sourceFilename, platformPath = path) {
7
6
  // Replace asset path with new path relative to the output CSS
@@ -13,6 +12,22 @@ export function transformUrl(url, outputFilename, sourceFilename, platformPath =
13
12
  }
14
13
  return relative.split(platformPath.sep).join(posixSep);
15
14
  }
15
+ function createStylisPreprocessor(options) {
16
+ function stylisPreprocess(selector, text) {
17
+ return serialize(compile(`${selector} {${text}}\n`), middleware([element => {
18
+ const {
19
+ outputFilename
20
+ } = options;
21
+ if (element.type === 'decl' && outputFilename) {
22
+ // When writing to a file, we need to adjust the relative paths inside url(..) expressions.
23
+ // It'll allow css-loader to resolve an imported asset properly.
24
+ // eslint-disable-next-line no-param-reassign
25
+ element.return = element.value.replace(/\b(url\((["']?))(\.[^)]+?)(\2\))/g, (match, p1, p2, p3, p4) => p1 + transformUrl(p3, outputFilename, options.filename) + p4);
26
+ }
27
+ }, namespace, prefixer, stringify]));
28
+ }
29
+ return stylisPreprocess;
30
+ }
16
31
  function extractCssFromAst(rules, originalCode, options) {
17
32
  const mappings = [];
18
33
  let cssText = '';
@@ -27,18 +42,7 @@ function extractCssFromAst(rules, originalCode, options) {
27
42
  break;
28
43
  case 'stylis':
29
44
  default:
30
- stylis.use(null)((context, decl) => {
31
- const {
32
- outputFilename
33
- } = options;
34
- if (context === STYLIS_DECLARATION && outputFilename) {
35
- // When writing to a file, we need to adjust the relative paths inside url(..) expressions
36
- // It'll allow css-loader to resolve an imported asset properly
37
- return decl.replace(/\b(url\((["']?))(\.[^)]+?)(\2\))/g, (match, p1, p2, p3, p4) => p1 + transformUrl(p3, outputFilename, options.filename) + p4);
38
- }
39
- return decl;
40
- });
41
- preprocessor = stylis;
45
+ preprocessor = createStylisPreprocessor(options);
42
46
  }
43
47
  }
44
48
  Object.keys(rules).forEach((selector, index) => {
@@ -1 +1 @@
1
- {"version":3,"file":"extract.js","names":["path","SourceMapGenerator","stylis","STYLIS_DECLARATION","posixSep","posix","sep","transformUrl","url","outputFilename","sourceFilename","platformPath","relative","dirname","resolve","split","join","extractCssFromAst","rules","originalCode","options","mappings","cssText","preprocessor","selector","text","use","context","decl","replace","match","p1","p2","p3","p4","filename","Object","keys","forEach","index","push","generated","line","column","original","start","name","source","atom","cssSourceMapText","length","generator","file","mapping","addMapping","setSourceContent","toString","extract","services","entrypoint","processors","data","loadedAndParsed","evaluator","Error","allRules","allReplacements","processor","artifacts","artifact","replacements","code"],"sources":["../../../src/transform/generators/extract.ts"],"sourcesContent":["import path from 'path';\n\nimport type { Mapping } from 'source-map';\nimport { SourceMapGenerator } from 'source-map';\nimport stylis from 'stylis';\n\nimport type { Replacements, Rules } from '@wyw-in-js/shared';\n\nimport type { Options, PreprocessorFn } from '../../types';\nimport type { IExtractAction, SyncScenarioForAction } from '../types';\n\nconst STYLIS_DECLARATION = 1;\nconst posixSep = path.posix.sep;\n\nexport function transformUrl(\n url: string,\n outputFilename: string,\n sourceFilename: string,\n platformPath: typeof path = path\n) {\n // Replace asset path with new path relative to the output CSS\n const relative = platformPath.relative(\n platformPath.dirname(outputFilename),\n // Get the absolute path to the asset from the path relative to the JS file\n platformPath.resolve(platformPath.dirname(sourceFilename), url)\n );\n\n if (platformPath.sep === posixSep) {\n return relative;\n }\n\n return relative.split(platformPath.sep).join(posixSep);\n}\n\nfunction extractCssFromAst(\n rules: Rules,\n originalCode: string,\n options: Pick<Options, 'preprocessor' | 'filename' | 'outputFilename'>\n): { cssSourceMapText: string; cssText: string; rules: Rules } {\n const mappings: Mapping[] = [];\n\n let cssText = '';\n\n let preprocessor: PreprocessorFn;\n if (typeof options.preprocessor === 'function') {\n // eslint-disable-next-line prefer-destructuring\n preprocessor = options.preprocessor;\n } else {\n switch (options.preprocessor) {\n case 'none':\n preprocessor = (selector, text) => `${selector} {${text}}\\n`;\n break;\n case 'stylis':\n default:\n stylis.use(null)((context, decl) => {\n const { outputFilename } = options;\n if (context === STYLIS_DECLARATION && outputFilename) {\n // When writing to a file, we need to adjust the relative paths inside url(..) expressions\n // It'll allow css-loader to resolve an imported asset properly\n return decl.replace(\n /\\b(url\\(([\"']?))(\\.[^)]+?)(\\2\\))/g,\n (match, p1, p2, p3, p4) =>\n p1 + transformUrl(p3, outputFilename, options.filename) + p4\n );\n }\n\n return decl;\n });\n\n preprocessor = stylis;\n }\n }\n\n Object.keys(rules).forEach((selector, index) => {\n mappings.push({\n generated: {\n line: index + 1,\n column: 0,\n },\n original: rules[selector].start!,\n name: selector,\n source: '',\n });\n\n if (rules[selector].atom) {\n // For atoms, we just directly insert cssText, to give the atomizer full control over the rules\n cssText += `${rules[selector].cssText}\\n`;\n } else {\n // Run each rule through stylis to support nesting\n cssText += `${preprocessor(selector, rules[selector].cssText)}\\n`;\n }\n });\n\n return {\n cssText,\n rules,\n\n get cssSourceMapText() {\n if (mappings?.length) {\n const generator = new SourceMapGenerator({\n file: options.filename.replace(/\\.js$/, '.css'),\n });\n\n mappings.forEach((mapping) =>\n generator.addMapping({ ...mapping, source: options.filename })\n );\n\n generator.setSourceContent(options.filename, originalCode);\n\n return generator.toString();\n }\n\n return '';\n },\n };\n}\n\n/**\n * Extract artifacts (e.g. CSS) from processors\n */\n// eslint-disable-next-line require-yield\nexport function* extract(\n this: IExtractAction\n): SyncScenarioForAction<IExtractAction> {\n const { options } = this.services;\n const { entrypoint } = this;\n const { processors } = this.data;\n const { loadedAndParsed } = entrypoint;\n if (loadedAndParsed.evaluator === 'ignored') {\n throw new Error('entrypoint was ignored');\n }\n\n let allRules: Rules = {};\n const allReplacements: Replacements = [];\n processors.forEach((processor) => {\n processor.artifacts.forEach((artifact) => {\n if (artifact[0] !== 'css') return;\n const [rules, replacements] = artifact[1] as [\n rules: Rules,\n sourceMapReplacements: Replacements,\n ];\n\n allRules = {\n ...allRules,\n ...rules,\n };\n\n allReplacements.push(...replacements);\n });\n });\n\n return {\n ...extractCssFromAst(allRules, loadedAndParsed.code, options),\n replacements: allReplacements,\n };\n}\n"],"mappings":"AAAA,OAAOA,IAAI,MAAM,MAAM;AAGvB,SAASC,kBAAkB,QAAQ,YAAY;AAC/C,OAAOC,MAAM,MAAM,QAAQ;AAO3B,MAAMC,kBAAkB,GAAG,CAAC;AAC5B,MAAMC,QAAQ,GAAGJ,IAAI,CAACK,KAAK,CAACC,GAAG;AAE/B,OAAO,SAASC,YAAYA,CAC1BC,GAAW,EACXC,cAAsB,EACtBC,cAAsB,EACtBC,YAAyB,GAAGX,IAAI,EAChC;EACA;EACA,MAAMY,QAAQ,GAAGD,YAAY,CAACC,QAAQ,CACpCD,YAAY,CAACE,OAAO,CAACJ,cAAc,CAAC;EACpC;EACAE,YAAY,CAACG,OAAO,CAACH,YAAY,CAACE,OAAO,CAACH,cAAc,CAAC,EAAEF,GAAG,CAChE,CAAC;EAED,IAAIG,YAAY,CAACL,GAAG,KAAKF,QAAQ,EAAE;IACjC,OAAOQ,QAAQ;EACjB;EAEA,OAAOA,QAAQ,CAACG,KAAK,CAACJ,YAAY,CAACL,GAAG,CAAC,CAACU,IAAI,CAACZ,QAAQ,CAAC;AACxD;AAEA,SAASa,iBAAiBA,CACxBC,KAAY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;EAC3C;EAEA,IAAIC,QAAe,GAAG,CAAC,CAAC;EACxB,MAAMC,eAA6B,GAAG,EAAE;EACxCN,UAAU,CAACtB,OAAO,CAAE6B,SAAS,IAAK;IAChCA,SAAS,CAACC,SAAS,CAAC9B,OAAO,CAAE+B,QAAQ,IAAK;MACxC,IAAIA,QAAQ,CAAC,CAAC,CAAC,KAAK,KAAK,EAAE;MAC3B,MAAM,CAACnD,KAAK,EAAEoD,YAAY,CAAC,GAAGD,QAAQ,CAAC,CAAC,CAGvC;MAEDJ,QAAQ,GAAG;QACT,GAAGA,QAAQ;QACX,GAAG/C;MACL,CAAC;MAEDgD,eAAe,CAAC1B,IAAI,CAAC,GAAG8B,YAAY,CAAC;IACvC,CAAC,CAAC;EACJ,CAAC,CAAC;EAEF,OAAO;IACL,GAAGrD,iBAAiB,CAACgD,QAAQ,EAAEH,eAAe,CAACS,IAAI,EAAEnD,OAAO,CAAC;IAC7DkD,YAAY,EAAEJ;EAChB,CAAC;AACH"}
1
+ {"version":3,"file":"extract.js","names":["path","SourceMapGenerator","compile","serialize","stringify","middleware","prefixer","namespace","posixSep","posix","sep","transformUrl","url","outputFilename","sourceFilename","platformPath","relative","dirname","resolve","split","join","createStylisPreprocessor","options","stylisPreprocess","selector","text","element","type","return","value","replace","match","p1","p2","p3","p4","filename","extractCssFromAst","rules","originalCode","mappings","cssText","preprocessor","Object","keys","forEach","index","push","generated","line","column","original","start","name","source","atom","cssSourceMapText","length","generator","file","mapping","addMapping","setSourceContent","toString","extract","services","entrypoint","processors","data","loadedAndParsed","evaluator","Error","allRules","allReplacements","processor","artifacts","artifact","replacements","code"],"sources":["../../../src/transform/generators/extract.ts"],"sourcesContent":["import path from 'path';\n\nimport type { Mapping } from 'source-map';\nimport { SourceMapGenerator } from 'source-map';\nimport {\n compile,\n serialize,\n stringify,\n middleware,\n prefixer,\n namespace,\n} from 'stylis';\n\nimport type { Replacements, Rules } from '@wyw-in-js/shared';\n\nimport type { Options, PreprocessorFn } from '../../types';\nimport type { IExtractAction, SyncScenarioForAction } from '../types';\n\nconst posixSep = path.posix.sep;\n\nexport function transformUrl(\n url: string,\n outputFilename: string,\n sourceFilename: string,\n platformPath: typeof path = path\n) {\n // Replace asset path with new path relative to the output CSS\n const relative = platformPath.relative(\n platformPath.dirname(outputFilename),\n // Get the absolute path to the asset from the path relative to the JS file\n platformPath.resolve(platformPath.dirname(sourceFilename), url)\n );\n\n if (platformPath.sep === posixSep) {\n return relative;\n }\n\n return relative.split(platformPath.sep).join(posixSep);\n}\n\nfunction createStylisPreprocessor(options: Options) {\n function stylisPreprocess(selector: string, text: string): string {\n return serialize(\n compile(`${selector} {${text}}\\n`),\n middleware([\n (element: { return: string; type: string; value: string }) => {\n const { outputFilename } = options;\n if (element.type === 'decl' && outputFilename) {\n // When writing to a file, we need to adjust the relative paths inside url(..) expressions.\n // It'll allow css-loader to resolve an imported asset properly.\n // eslint-disable-next-line no-param-reassign\n element.return = element.value.replace(\n /\\b(url\\(([\"']?))(\\.[^)]+?)(\\2\\))/g,\n (match, p1, p2, p3, p4) =>\n p1 + transformUrl(p3, outputFilename, options.filename) + p4\n );\n }\n },\n namespace,\n prefixer,\n stringify,\n ])\n );\n }\n return stylisPreprocess;\n}\n\nfunction extractCssFromAst(\n rules: Rules,\n originalCode: string,\n options: Pick<Options, 'preprocessor' | 'filename' | 'outputFilename'>\n): { cssSourceMapText: string; cssText: string; rules: Rules } {\n const mappings: Mapping[] = [];\n\n let cssText = '';\n\n let preprocessor: PreprocessorFn;\n if (typeof options.preprocessor === 'function') {\n // eslint-disable-next-line prefer-destructuring\n preprocessor = options.preprocessor;\n } else {\n switch (options.preprocessor) {\n case 'none':\n preprocessor = (selector, text) => `${selector} {${text}}\\n`;\n break;\n case 'stylis':\n default:\n preprocessor = createStylisPreprocessor(options);\n }\n }\n\n Object.keys(rules).forEach((selector, index) => {\n mappings.push({\n generated: {\n line: index + 1,\n column: 0,\n },\n original: rules[selector].start!,\n name: selector,\n source: '',\n });\n\n if (rules[selector].atom) {\n // For atoms, we just directly insert cssText, to give the atomizer full control over the rules\n cssText += `${rules[selector].cssText}\\n`;\n } else {\n // Run each rule through stylis to support nesting\n cssText += `${preprocessor(selector, rules[selector].cssText)}\\n`;\n }\n });\n\n return {\n cssText,\n rules,\n\n get cssSourceMapText() {\n if (mappings?.length) {\n const generator = new SourceMapGenerator({\n file: options.filename.replace(/\\.js$/, '.css'),\n });\n\n mappings.forEach((mapping) =>\n generator.addMapping({ ...mapping, source: options.filename })\n );\n\n generator.setSourceContent(options.filename, originalCode);\n\n return generator.toString();\n }\n\n return '';\n },\n };\n}\n\n/**\n * Extract artifacts (e.g. CSS) from processors\n */\n// eslint-disable-next-line require-yield\nexport function* extract(\n this: IExtractAction\n): SyncScenarioForAction<IExtractAction> {\n const { options } = this.services;\n const { entrypoint } = this;\n const { processors } = this.data;\n const { loadedAndParsed } = entrypoint;\n if (loadedAndParsed.evaluator === 'ignored') {\n throw new Error('entrypoint was ignored');\n }\n\n let allRules: Rules = {};\n const allReplacements: Replacements = [];\n processors.forEach((processor) => {\n processor.artifacts.forEach((artifact) => {\n if (artifact[0] !== 'css') return;\n const [rules, replacements] = artifact[1] as [\n rules: Rules,\n sourceMapReplacements: Replacements,\n ];\n\n allRules = {\n ...allRules,\n ...rules,\n };\n\n allReplacements.push(...replacements);\n });\n });\n\n return {\n ...extractCssFromAst(allRules, loadedAndParsed.code, options),\n replacements: allReplacements,\n };\n}\n"],"mappings":"AAAA,OAAOA,IAAI,MAAM,MAAM;AAGvB,SAASC,kBAAkB,QAAQ,YAAY;AAC/C,SACEC,OAAO,EACPC,SAAS,EACTC,SAAS,EACTC,UAAU,EACVC,QAAQ,EACRC,SAAS,QACJ,QAAQ;AAOf,MAAMC,QAAQ,GAAGR,IAAI,CAACS,KAAK,CAACC,GAAG;AAE/B,OAAO,SAASC,YAAYA,CAC1BC,GAAW,EACXC,cAAsB,EACtBC,cAAsB,EACtBC,YAAyB,GAAGf,IAAI,EAChC;EACA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O,CAAC;IAC7DuD,YAAY,EAAEJ;EAChB,CAAC;AACH"}
@@ -14,7 +14,7 @@ function runPreevalStage(babel, evalConfig, pluginOptions, code, originalAst, ev
14
14
  }], [require.resolve('../../plugins/dynamic-import')], ...(evalConfig.plugins ?? []).filter(i => !hasKeyInList(i, pluginOptions.highPriorityPlugins))];
15
15
  const transformConfig = buildOptions({
16
16
  ...evalConfig,
17
- envName: 'linaria',
17
+ envName: 'wyw-in-js',
18
18
  plugins
19
19
  });
20
20
  const result = babel.transformFromAstSync(originalAst, code, transformConfig);
@@ -48,7 +48,7 @@ export const prepareCode = (services, item, originalAst) => {
48
48
  } = options;
49
49
  const preevalStageResult = eventEmitter.perf('transform:preeval', () => runPreevalStage(babel, evalConfig, pluginOptions, code, originalAst, eventEmitter));
50
50
  const transformMetadata = getTransformMetadata(preevalStageResult.metadata);
51
- if (only.length === 1 && only[0] === '__linariaPreval' && !transformMetadata) {
51
+ if (only.length === 1 && only[0] === '__wywPreval' && !transformMetadata) {
52
52
  log('[evaluator:end] no metadata');
53
53
  return [preevalStageResult.code, null, null];
54
54
  }
@@ -1 +1 @@
1
- {"version":3,"file":"transform.js","names":["buildOptions","getTransformMetadata","getPluginKey","EMPTY_FILE","hasKeyInList","plugin","list","pluginKey","some","i","includes","runPreevalStage","babel","evalConfig","pluginOptions","code","originalAst","eventEmitter","preShakePlugins","plugins","filter","highPriorityPlugins","require","resolve","transformConfig","envName","result","transformFromAstSync","ast","program","Error","prepareCode","services","item","log","only","loadedAndParsed","evaluator","options","preevalStageResult","perf","transformMetadata","metadata","length","name","evaluatorConfig","onlyExports","features","transformedCode","imports","internalTransform","prepareFn","entrypoint","preparedCode","extend","size","resolvedImports","getNext","resolved","transform","call"],"sources":["../../../src/transform/generators/transform.ts"],"sourcesContent":["import type {\n BabelFileResult,\n PluginItem,\n TransformOptions,\n} from '@babel/core';\nimport type { File } from '@babel/types';\n\nimport type { EvaluatorConfig, StrictOptions } from '@wyw-in-js/shared';\n\nimport type { Core } from '../../babel';\nimport { buildOptions } from '../../options/buildOptions';\nimport type { EventEmitter } from '../../utils/EventEmitter';\nimport type { WYWTransformMetadata } from '../../utils/TransformMetadata';\nimport { getTransformMetadata } from '../../utils/TransformMetadata';\nimport { getPluginKey } from '../../utils/getPluginKey';\nimport type { Entrypoint } from '../Entrypoint';\nimport type {\n ITransformAction,\n Services,\n SyncScenarioForAction,\n} from '../types';\n\nconst EMPTY_FILE = '=== empty file ===';\n\nconst hasKeyInList = (plugin: PluginItem, list: string[]): boolean => {\n const pluginKey = getPluginKey(plugin);\n return pluginKey ? list.some((i) => pluginKey.includes(i)) : false;\n};\n\nfunction runPreevalStage(\n babel: Core,\n evalConfig: TransformOptions,\n pluginOptions: StrictOptions,\n code: string,\n originalAst: File,\n eventEmitter: EventEmitter\n): BabelFileResult {\n const preShakePlugins =\n evalConfig.plugins?.filter((i) =>\n hasKeyInList(i, pluginOptions.highPriorityPlugins)\n ) ?? [];\n\n const plugins = [\n ...preShakePlugins,\n [\n require.resolve('../../plugins/preeval'),\n { ...pluginOptions, eventEmitter },\n ],\n [require.resolve('../../plugins/dynamic-import')],\n ...(evalConfig.plugins ?? []).filter(\n (i) => !hasKeyInList(i, pluginOptions.highPriorityPlugins)\n ),\n ];\n\n const transformConfig = buildOptions({\n ...evalConfig,\n envName: 'linaria',\n plugins,\n });\n\n const result = babel.transformFromAstSync(originalAst, code, transformConfig);\n\n if (!result || !result.ast?.program) {\n throw new Error('Babel transform failed');\n }\n\n return result;\n}\n\ntype PrepareCodeFn = (\n services: Services,\n item: Entrypoint,\n originalAst: File\n) => [\n code: string,\n imports: Map<string, string[]> | null,\n metadata: WYWTransformMetadata | null,\n];\n\nexport const prepareCode = (\n services: Services,\n item: Entrypoint,\n originalAst: File\n): ReturnType<PrepareCodeFn> => {\n const { log, only, loadedAndParsed } = item;\n if (loadedAndParsed.evaluator === 'ignored') {\n log('is ignored');\n return [loadedAndParsed.code ?? '', null, null];\n }\n\n const { code, evalConfig, evaluator } = loadedAndParsed;\n const { options, babel, eventEmitter } = services;\n const { pluginOptions } = options;\n\n const preevalStageResult = eventEmitter.perf('transform:preeval', () =>\n runPreevalStage(\n babel,\n evalConfig,\n pluginOptions,\n code,\n originalAst,\n eventEmitter\n )\n );\n\n const transformMetadata = getTransformMetadata(preevalStageResult.metadata);\n\n if (\n only.length === 1 &&\n only[0] === '__linariaPreval' &&\n !transformMetadata\n ) {\n log('[evaluator:end] no metadata');\n return [preevalStageResult.code!, null, null];\n }\n\n log('[preeval] metadata %O', transformMetadata);\n log('[evaluator:start] using %s', evaluator.name);\n\n const evaluatorConfig: EvaluatorConfig = {\n onlyExports: only,\n highPriorityPlugins: pluginOptions.highPriorityPlugins,\n features: pluginOptions.features,\n };\n\n const [, transformedCode, imports] = eventEmitter.perf(\n 'transform:evaluator',\n () =>\n evaluator(\n evalConfig,\n preevalStageResult.ast!,\n preevalStageResult.code!,\n evaluatorConfig,\n babel\n )\n );\n\n log('[evaluator:end]');\n\n return [transformedCode, imports, transformMetadata ?? null];\n};\n\nexport function* internalTransform(\n this: ITransformAction,\n prepareFn: PrepareCodeFn\n): SyncScenarioForAction<ITransformAction> {\n const { only, loadedAndParsed, log } = this.entrypoint;\n if (loadedAndParsed.evaluator === 'ignored') {\n log('is ignored');\n return {\n code: loadedAndParsed.code ?? '',\n metadata: null,\n };\n }\n\n log('>> (%o)', only);\n\n const [preparedCode, imports, metadata] = prepareFn(\n this.services,\n this.entrypoint,\n loadedAndParsed.ast\n );\n\n if (loadedAndParsed.code === preparedCode) {\n log('<< (%o)\\n === no changes ===', only);\n } else {\n log('<< (%o)', only);\n log.extend('source')('%s', preparedCode || EMPTY_FILE);\n }\n\n if (preparedCode === '') {\n log('is skipped');\n return {\n code: loadedAndParsed.code ?? '',\n metadata: null,\n };\n }\n\n if (imports !== null && imports.size > 0) {\n const resolvedImports = yield* this.getNext(\n 'resolveImports',\n this.entrypoint,\n {\n imports,\n }\n );\n\n if (resolvedImports.length !== 0) {\n yield [\n 'processImports',\n this.entrypoint,\n {\n resolved: resolvedImports,\n },\n ];\n }\n }\n\n return {\n code: preparedCode,\n metadata,\n };\n}\n\n/**\n * Prepares the code for evaluation. This includes removing dead and potentially unsafe code.\n * Emits resolveImports and processImports events.\n */\nexport function transform(this: ITransformAction) {\n return internalTransform.call(this, prepareCode);\n}\n"],"mappings":"AAUA,SAASA,YAAY,QAAQ,4BAA4B;AAGzD,SAASC,oBAAoB,QAAQ,+BAA+B;AACpE,SAASC,YAAY,QAAQ,0BAA0B;AAQvD,MAAMC,UAAU,GAAG,oBAAoB;AAEvC,MAAMC,YAAY,GAAGA,CAACC,MAAkB,EAAEC,IAAc,KAAc;EACpE,MAAMC,SAAS,GAAGL,YAAY,CAACG,MAAM,CAAC;EACtC,OAAOE,SAAS,GAAGD,IAAI,CAACE,IAAI,CAAEC,CAAC,IAAKF,SAAS,CAACG,QAAQ,CAACD,CAAC,CAAC,CAAC,GAAG,KAAK;AACpE,CAAC;AAED,SAASE,eAAeA,CACtBC,KAAW,EACXC,UAA4B,EAC5BC,aAA4B,EAC5BC,IAAY,EACZC,WAAiB,EACjBC,YAA0B,EACT;EACjB,MAAMC,eAAe,GACnBL,UAAU,CAACM,OAAO,EAAEC,MAAM,CAAEX,CAAC,IAC3BL,YAAY,CAACK,CAAC,EAAEK,aAAa,CAACO,mBAAmB,CACnD,CAAC,IAAI,EAAE;EAET,MAAMF,OAAO,GAAG,CACd,GAAGD,eAAe,EAClB,CACEI,OAAO,CAACC,OAAO,CAAC,uBAAuB,CAAC,EACxC;IAAE,GAAGT,aAAa;IAAEG;EAAa,CAAC,CACnC,EACD,CAACK,OAAO,CAACC,OAAO,CAAC,8BAA8B,CAAC,CAAC,EACjD,GAAG,CAACV,UAAU,CAACM,OAAO,IAAI,EAAE,EAAEC,MAAM,CACjCX,CAAC,IAAK,CAACL,YAAY,CAACK,CAAC,EAAEK,aAAa,CAACO,mBAAmB,CAC3D,CAAC,CACF;EAED,MAAMG,eAAe,GAAGx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,EAAE;IACzCnB,GAAG,CAAC,8BAA8B,EAAEC,IAAI,CAAC;EAC3C,CAAC,MAAM;IACLD,GAAG,CAAC,SAAS,EAAEC,IAAI,CAAC;IACpBD,GAAG,CAACoB,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,EAAED,YAAY,IAAIlD,UAAU,CAAC;EACxD;EAEA,IAAIkD,YAAY,KAAK,EAAE,EAAE;IACvBnB,GAAG,CAAC,YAAY,CAAC;IACjB,OAAO;MACLnB,IAAI,EAAEqB,eAAe,CAACrB,IAAI,IAAI,EAAE;MAChC2B,QAAQ,EAAE;IACZ,CAAC;EACH;EAEA,IAAIO,OAAO,KAAK,IAAI,IAAIA,OAAO,CAACM,IAAI,GAAG,CAAC,EAAE;IACxC,MAAMC,eAAe,GAAG,OAAO,IAAI,CAACC,OAAO,CACzC,gBAAgB,EAChB,IAAI,CAACL,UAAU,EACf;MACEH;IACF,CACF,CAAC;IAED,IAAIO,eAAe,CAACb,MAAM,KAAK,CAAC,EAAE;MAChC,MAAM,CACJ,gBAAgB,EAChB,IAAI,CAACS,UAAU,EACf;QACEM,QAAQ,EAAEF;MACZ,CAAC,CACF;IACH;EACF;EAEA,OAAO;IACLzC,IAAI,EAAEsC,YAAY;IAClBX;EACF,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASiB,SAASA,CAAA,EAAyB;EAChD,OAAOT,iBAAiB,CAACU,IAAI,CAAC,IAAI,EAAE7B,WAAW,CAAC;AAClD"}
1
+ {"version":3,"file":"transform.js","names":["buildOptions","getTransformMetadata","getPluginKey","EMPTY_FILE","hasKeyInList","plugin","list","pluginKey","some","i","includes","runPreevalStage","babel","evalConfig","pluginOptions","code","originalAst","eventEmitter","preShakePlugins","plugins","filter","highPriorityPlugins","require","resolve","transformConfig","envName","result","transformFromAstSync","ast","program","Error","prepareCode","services","item","log","only","loadedAndParsed","evaluator","options","preevalStageResult","perf","transformMetadata","metadata","length","name","evaluatorConfig","onlyExports","features","transformedCode","imports","internalTransform","prepareFn","entrypoint","preparedCode","extend","size","resolvedImports","getNext","resolved","transform","call"],"sources":["../../../src/transform/generators/transform.ts"],"sourcesContent":["import type {\n BabelFileResult,\n PluginItem,\n TransformOptions,\n} from '@babel/core';\nimport type { File } from '@babel/types';\n\nimport type { EvaluatorConfig, StrictOptions } from '@wyw-in-js/shared';\n\nimport type { Core } from '../../babel';\nimport { buildOptions } from '../../options/buildOptions';\nimport type { EventEmitter } from '../../utils/EventEmitter';\nimport type { WYWTransformMetadata } from '../../utils/TransformMetadata';\nimport { getTransformMetadata } from '../../utils/TransformMetadata';\nimport { getPluginKey } from '../../utils/getPluginKey';\nimport type { Entrypoint } from '../Entrypoint';\nimport type {\n ITransformAction,\n Services,\n SyncScenarioForAction,\n} from '../types';\n\nconst EMPTY_FILE = '=== empty file ===';\n\nconst hasKeyInList = (plugin: PluginItem, list: string[]): boolean => {\n const pluginKey = getPluginKey(plugin);\n return pluginKey ? list.some((i) => pluginKey.includes(i)) : false;\n};\n\nfunction runPreevalStage(\n babel: Core,\n evalConfig: TransformOptions,\n pluginOptions: StrictOptions,\n code: string,\n originalAst: File,\n eventEmitter: EventEmitter\n): BabelFileResult {\n const preShakePlugins =\n evalConfig.plugins?.filter((i) =>\n hasKeyInList(i, pluginOptions.highPriorityPlugins)\n ) ?? [];\n\n const plugins = [\n ...preShakePlugins,\n [\n require.resolve('../../plugins/preeval'),\n { ...pluginOptions, eventEmitter },\n ],\n [require.resolve('../../plugins/dynamic-import')],\n ...(evalConfig.plugins ?? []).filter(\n (i) => !hasKeyInList(i, pluginOptions.highPriorityPlugins)\n ),\n ];\n\n const transformConfig = buildOptions({\n ...evalConfig,\n envName: 'wyw-in-js',\n plugins,\n });\n\n const result = babel.transformFromAstSync(originalAst, code, transformConfig);\n\n if (!result || !result.ast?.program) {\n throw new Error('Babel transform failed');\n }\n\n return result;\n}\n\ntype PrepareCodeFn = (\n services: Services,\n item: Entrypoint,\n originalAst: File\n) => [\n code: string,\n imports: Map<string, string[]> | null,\n metadata: WYWTransformMetadata | null,\n];\n\nexport const prepareCode = (\n services: Services,\n item: Entrypoint,\n originalAst: File\n): ReturnType<PrepareCodeFn> => {\n const { log, only, loadedAndParsed } = item;\n if (loadedAndParsed.evaluator === 'ignored') {\n log('is ignored');\n return [loadedAndParsed.code ?? '', null, null];\n }\n\n const { code, evalConfig, evaluator } = loadedAndParsed;\n const { options, babel, eventEmitter } = services;\n const { pluginOptions } = options;\n\n const preevalStageResult = eventEmitter.perf('transform:preeval', () =>\n runPreevalStage(\n babel,\n evalConfig,\n pluginOptions,\n code,\n originalAst,\n eventEmitter\n )\n );\n\n const transformMetadata = getTransformMetadata(preevalStageResult.metadata);\n\n if (only.length === 1 && only[0] === '__wywPreval' && !transformMetadata) {\n log('[evaluator:end] no metadata');\n return [preevalStageResult.code!, null, null];\n }\n\n log('[preeval] metadata %O', transformMetadata);\n log('[evaluator:start] using %s', evaluator.name);\n\n const evaluatorConfig: EvaluatorConfig = {\n onlyExports: only,\n highPriorityPlugins: pluginOptions.highPriorityPlugins,\n features: pluginOptions.features,\n };\n\n const [, transformedCode, imports] = eventEmitter.perf(\n 'transform:evaluator',\n () =>\n evaluator(\n evalConfig,\n preevalStageResult.ast!,\n preevalStageResult.code!,\n evaluatorConfig,\n babel\n )\n );\n\n log('[evaluator:end]');\n\n return [transformedCode, imports, transformMetadata ?? null];\n};\n\nexport function* internalTransform(\n this: ITransformAction,\n prepareFn: PrepareCodeFn\n): SyncScenarioForAction<ITransformAction> {\n const { only, loadedAndParsed, log } = this.entrypoint;\n if (loadedAndParsed.evaluator === 'ignored') {\n log('is ignored');\n return {\n code: loadedAndParsed.code ?? '',\n metadata: null,\n };\n }\n\n log('>> (%o)', only);\n\n const [preparedCode, imports, metadata] = prepareFn(\n this.services,\n this.entrypoint,\n loadedAndParsed.ast\n );\n\n if (loadedAndParsed.code === preparedCode) {\n log('<< (%o)\\n === no changes ===', only);\n } else {\n log('<< (%o)', only);\n log.extend('source')('%s', preparedCode || EMPTY_FILE);\n }\n\n if (preparedCode === '') {\n log('is skipped');\n return {\n code: loadedAndParsed.code ?? '',\n metadata: null,\n };\n }\n\n if (imports !== null && imports.size > 0) {\n const resolvedImports = yield* this.getNext(\n 'resolveImports',\n this.entrypoint,\n {\n imports,\n }\n );\n\n if (resolvedImports.length !== 0) {\n yield [\n 'processImports',\n this.entrypoint,\n {\n resolved: resolvedImports,\n },\n ];\n }\n }\n\n return {\n code: preparedCode,\n metadata,\n };\n}\n\n/**\n * Prepares the code for evaluation. This includes removing dead and potentially unsafe code.\n * Emits resolveImports and processImports events.\n */\nexport function transform(this: ITransformAction) {\n return internalTransform.call(this, prepareCode);\n}\n"],"mappings":"AAUA,SAASA,YAAY,QAAQ,4BAA4B;AAGzD,SAASC,oBAAoB,QAAQ,+BAA+B;AACpE,SAASC,YAAY,QAAQ,0BAA0B;AAQvD,MAAMC,UAAU,GAAG,oBAAoB;AAEvC,MAAMC,YAAY,GAAGA,CAACC,MAAkB,EAAEC,IAAc,KAAc;EACpE,MAAMC,SAAS,GAAGL,YAAY,CAACG,MAAM,CAAC;EACtC,OAAOE,SAAS,GAAGD,IAAI,CAACE,IAAI,CAAEC,CAAC,IAAKF,SAAS,CAACG,QAAQ,CAACD,CAAC,CAAC,CAAC,GAAG,KAAK;AACpE,CAAC;AAED,SAASE,eAAeA,CACtBC,KAAW,EACXC,UAA4B,EAC5BC,aAA4B,EAC5BC,IAAY,EACZC,WAAiB,EACjBC,YAA0B,EACT;EACjB,MAAMC,eAAe,GACnBL,UAAU,CAACM,OAAO,EAAEC,MAAM,CAAEX,CAAC,IAC3BL,YAAY,CAACK,CAAC,EAAEK,aAAa,CAACO,mBAAmB,CACnD,CAAC,IAAI,EAAE;EAET,MAAMF,OAAO,GAAG,CACd,GAAGD,eAAe,EAClB,CACEI,OAAO,CAACC,OAAO,CAAC,uBAAuB,CAAC,EACxC;IAAE,GAAGT,aAAa;IAAEG;EAAa,CAAC,CACnC,EACD,CAACK,O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C,IAAI,CAAC;EAEpB,MAAM,CAACkB,YAAY,EAAEJ,OAAO,EAAEP,QAAQ,CAAC,GAAGS,SAAS,CACjD,IAAI,CAACnB,QAAQ,EACb,IAAI,CAACoB,UAAU,EACfhB,eAAe,CAACR,GAClB,CAAC;EAED,IAAIQ,eAAe,CAACrB,IAAI,KAAKsC,YAAY,EAAE;IACzCnB,GAAG,CAAC,8BAA8B,EAAEC,IAAI,CAAC;EAC3C,CAAC,MAAM;IACLD,GAAG,CAAC,SAAS,EAAEC,IAAI,CAAC;IACpBD,GAAG,CAACoB,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,EAAED,YAAY,IAAIlD,UAAU,CAAC;EACxD;EAEA,IAAIkD,YAAY,KAAK,EAAE,EAAE;IACvBnB,GAAG,CAAC,YAAY,CAAC;IACjB,OAAO;MACLnB,IAAI,EAAEqB,eAAe,CAACrB,IAAI,IAAI,EAAE;MAChC2B,QAAQ,EAAE;IACZ,CAAC;EACH;EAEA,IAAIO,OAAO,KAAK,IAAI,IAAIA,OAAO,CAACM,IAAI,GAAG,CAAC,EAAE;IACxC,MAAMC,eAAe,GAAG,OAAO,IAAI,CAACC,OAAO,CACzC,gBAAgB,EAChB,IAAI,CAACL,UAAU,EACf;MACEH;IACF,CACF,CAAC;IAED,IAAIO,eAAe,CAACb,MAAM,KAAK,CAAC,EAAE;MAChC,MAAM,CACJ,gBAAgB,EAChB,IAAI,CAACS,UAAU,EACf;QACEM,QAAQ,EAAEF;MACZ,CAAC,CACF;IACH;EACF;EAEA,OAAO;IACLzC,IAAI,EAAEsC,YAAY;IAClBX;EACF,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASiB,SAASA,CAAA,EAAyB;EAChD,OAAOT,iBAAiB,CAACU,IAAI,CAAC,IAAI,EAAE7B,WAAW,CAAC;AAClD"}
@@ -31,10 +31,10 @@ export function* workflow() {
31
31
  const originalCode = entrypoint.loadedAndParsed.code ?? '';
32
32
 
33
33
  // File is ignored or does not contain any tags. Return original code.
34
- if (!entrypoint.hasLinariaMetadata()) {
34
+ if (!entrypoint.hasWywMetadata()) {
35
35
  if (entrypoint.generation === 1) {
36
- // 1st generation here means that it's __linariaPreval entrypoint
37
- // without __linariaPreval, so we don't need it cached
36
+ // 1st generation here means that it's __wywPreval entrypoint
37
+ // without __wywPreval, so we don't need it cached
38
38
  cache.delete('entrypoints', entrypoint.name);
39
39
  }
40
40
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"workflow.js","names":["isAborted","workflow","cache","options","services","entrypoint","ignored","code","loadedAndParsed","sourceMap","inputSourceMap","getNext","undefined","assertNotSuperseded","e","supersededWith","log","originalCode","hasLinariaMetadata","generation","delete","name","evalStageResult","valueCache","dependencies","collectStageResult","metadata","map","extractStageResult","processors","replacements"],"sources":["../../../src/transform/generators/workflow.ts"],"sourcesContent":["import { isAborted } from '../actions/AbortError';\nimport type { IWorkflowAction, SyncScenarioForAction } from '../types';\n\n/**\n * The entry point for file processing. Sequentially calls `processEntrypoint`,\n * `evalFile`, `collect`, and `extract`. Returns the result of transforming\n * the source code as well as all artifacts obtained from code execution.\n */\nexport function* workflow(\n this: IWorkflowAction\n): SyncScenarioForAction<IWorkflowAction> {\n const { cache, options } = this.services;\n const { entrypoint } = this;\n\n if (entrypoint.ignored) {\n return {\n code: entrypoint.loadedAndParsed.code ?? '',\n sourceMap: options.inputSourceMap,\n };\n }\n\n try {\n yield* this.getNext('processEntrypoint', entrypoint, undefined, null);\n entrypoint.assertNotSuperseded();\n } catch (e) {\n if (isAborted(e) && entrypoint.supersededWith) {\n entrypoint.log('workflow aborted, schedule the next attempt');\n return yield* this.getNext(\n 'workflow',\n entrypoint.supersededWith,\n undefined,\n null\n );\n }\n\n throw e;\n }\n\n const originalCode = entrypoint.loadedAndParsed.code ?? '';\n\n // File is ignored or does not contain any tags. Return original code.\n if (!entrypoint.hasLinariaMetadata()) {\n if (entrypoint.generation === 1) {\n // 1st generation here means that it's __linariaPreval entrypoint\n // without __linariaPreval, so we don't need it cached\n cache.delete('entrypoints', entrypoint.name);\n }\n\n return {\n code: originalCode,\n sourceMap: options.inputSourceMap,\n };\n }\n\n // *** 2nd stage ***\n\n const evalStageResult = yield* this.getNext(\n 'evalFile',\n entrypoint,\n undefined,\n null\n );\n\n if (evalStageResult === null) {\n return {\n code: originalCode,\n sourceMap: options.inputSourceMap,\n };\n }\n\n const [valueCache, dependencies] = evalStageResult;\n\n // *** 3rd stage ***\n\n const collectStageResult = yield* this.getNext(\n 'collect',\n entrypoint,\n {\n valueCache,\n },\n null\n );\n\n if (!collectStageResult.metadata) {\n return {\n code: collectStageResult.code!,\n sourceMap: collectStageResult.map,\n };\n }\n\n // *** 4th stage\n\n const extractStageResult = yield* this.getNext(\n 'extract',\n entrypoint,\n {\n processors: collectStageResult.metadata.processors,\n },\n null\n );\n\n return {\n ...extractStageResult,\n code: collectStageResult.code ?? '',\n dependencies,\n replacements: [\n ...extractStageResult.replacements,\n ...collectStageResult.metadata.replacements,\n ],\n sourceMap: collectStageResult.map,\n };\n}\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,uBAAuB;AAGjD;AACA;AACA;AACA;AACA;AACA,OAAO,UAAUC,QAAQA,CAAA,EAEiB;EACxC,MAAM;IAAEC,KAAK;IAAEC;EAAQ,CAAC,GAAG,IAAI,CAACC,QAAQ;EACxC,MAAM;IAAEC;EAAW,CAAC,GAAG,IAAI;EAE3B,IAAIA,UAAU,CAACC,OAAO,EAAE;IACtB,OAAO;MACLC,IAAI,EAAEF,UAAU,CAACG,eAAe,CAACD,IAAI,IAAI,EAAE;MAC3CE,SAAS,EAAEN,OAAO,CAACO;IACrB,CAAC;EACH;EAEA,IAAI;IACF,OAAO,IAAI,CAACC,OAAO,CAAC,mBAAmB,EAAEN,UAAU,EAAEO,SAAS,EAAE,IAAI,CAAC;IACrEP,UAAU,CAACQ,mBAAmB,CAAC,CAAC;EAClC,CAAC,CAAC,OAAOC,CAAC,EAAE;IACV,IAAId,SAAS,CA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UAAU,EACV;IACEwB,UAAU,EAAEJ,kBAAkB,CAACC,QAAQ,CAACG;EAC1C,CAAC,EACD,IACF,CAAC;EAED,OAAO;IACL,GAAGD,kBAAkB;IACrBrB,IAAI,EAAEkB,kBAAkB,CAAClB,IAAI,IAAI,EAAE;IACnCiB,YAAY;IACZM,YAAY,EAAE,CACZ,GAAGF,kBAAkB,CAACE,YAAY,EAClC,GAAGL,kBAAkB,CAACC,QAAQ,CAACI,YAAY,CAC5C;IACDrB,SAAS,EAAEgB,kBAAkB,CAACE;EAChC,CAAC;AACH"}
1
+ {"version":3,"file":"workflow.js","names":["isAborted","workflow","cache","options","services","entrypoint","ignored","code","loadedAndParsed","sourceMap","inputSourceMap","getNext","undefined","assertNotSuperseded","e","supersededWith","log","originalCode","hasWywMetadata","generation","delete","name","evalStageResult","valueCache","dependencies","collectStageResult","metadata","map","extractStageResult","processors","replacements"],"sources":["../../../src/transform/generators/workflow.ts"],"sourcesContent":["import { isAborted } from '../actions/AbortError';\nimport type { IWorkflowAction, SyncScenarioForAction } from '../types';\n\n/**\n * The entry point for file processing. Sequentially calls `processEntrypoint`,\n * `evalFile`, `collect`, and `extract`. Returns the result of transforming\n * the source code as well as all artifacts obtained from code execution.\n */\nexport function* workflow(\n this: IWorkflowAction\n): SyncScenarioForAction<IWorkflowAction> {\n const { cache, options } = this.services;\n const { entrypoint } = this;\n\n if (entrypoint.ignored) {\n return {\n code: entrypoint.loadedAndParsed.code ?? '',\n sourceMap: options.inputSourceMap,\n };\n }\n\n try {\n yield* this.getNext('processEntrypoint', entrypoint, undefined, null);\n entrypoint.assertNotSuperseded();\n } catch (e) {\n if (isAborted(e) && entrypoint.supersededWith) {\n entrypoint.log('workflow aborted, schedule the next attempt');\n return yield* this.getNext(\n 'workflow',\n entrypoint.supersededWith,\n undefined,\n null\n );\n }\n\n throw e;\n }\n\n const originalCode = entrypoint.loadedAndParsed.code ?? '';\n\n // File is ignored or does not contain any tags. Return original code.\n if (!entrypoint.hasWywMetadata()) {\n if (entrypoint.generation === 1) {\n // 1st generation here means that it's __wywPreval entrypoint\n // without __wywPreval, so we don't need it cached\n cache.delete('entrypoints', entrypoint.name);\n }\n\n return {\n code: originalCode,\n sourceMap: options.inputSourceMap,\n };\n }\n\n // *** 2nd stage ***\n\n const evalStageResult = yield* this.getNext(\n 'evalFile',\n entrypoint,\n undefined,\n null\n );\n\n if (evalStageResult === null) {\n return {\n code: originalCode,\n sourceMap: options.inputSourceMap,\n };\n }\n\n const [valueCache, dependencies] = evalStageResult;\n\n // *** 3rd stage ***\n\n const collectStageResult = yield* this.getNext(\n 'collect',\n entrypoint,\n {\n valueCache,\n },\n null\n );\n\n if (!collectStageResult.metadata) {\n return {\n code: collectStageResult.code!,\n sourceMap: collectStageResult.map,\n };\n }\n\n // *** 4th stage\n\n const extractStageResult = yield* this.getNext(\n 'extract',\n entrypoint,\n {\n processors: collectStageResult.metadata.processors,\n },\n null\n );\n\n return {\n ...extractStageResult,\n code: collectStageResult.code ?? '',\n dependencies,\n replacements: [\n ...extractStageResult.replacements,\n ...collectStageResult.metadata.replacements,\n ],\n sourceMap: collectStageResult.map,\n };\n}\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,uBAAuB;AAGjD;AACA;AACA;AACA;AACA;AACA,OAAO,UAAUC,QAAQA,CAAA,EAEiB;EACxC,MAAM;IAAEC,KAAK;IAAEC;EAAQ,CAAC,GAAG,IAAI,CAACC,QAAQ;EACxC,MAAM;IAAEC;EAAW,CAAC,GAAG,IAAI;EAE3B,IAAIA,UAAU,CAACC,OAAO,EAAE;IACtB,OAAO;MACLC,IAAI,EAAEF,UAAU,CAACG,eAAe,CAACD,IAAI,IAAI,EAAE;MAC3CE,SAAS,EAAEN,OAAO,CAACO;IACrB,CAAC;EACH;EAEA,IAAI;IACF,OAAO,IAAI,CAACC,OAAO,CAAC,mBAAmB,EAAEN,UAAU,EAAEO,SAAS,EAAE,IAAI,CAAC;IACrEP,UAAU,CAACQ,mBAAmB,CAAC,C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kBAAkB,GAAG,OAAO,IAAI,CAACjB,OAAO,CAC5C,SAAS,EACTN,UAAU,EACV;IACEwB,UAAU,EAAEJ,kBAAkB,CAACC,QAAQ,CAACG;EAC1C,CAAC,EACD,IACF,CAAC;EAED,OAAO;IACL,GAAGD,kBAAkB;IACrBrB,IAAI,EAAEkB,kBAAkB,CAAClB,IAAI,IAAI,EAAE;IACnCiB,YAAY;IACZM,YAAY,EAAE,CACZ,GAAGF,kBAAkB,CAACE,YAAY,EAClC,GAAGL,kBAAkB,CAACC,QAAQ,CAACI,YAAY,CAC5C;IACDrB,SAAS,EAAEgB,kBAAkB,CAACE;EAChC,CAAC;AACH"}
@@ -1,13 +1,13 @@
1
1
  import { cosmiconfigSync } from 'cosmiconfig';
2
2
  import shaker from '../../shaker';
3
- const searchPlaces = [`.linariarc`, `.linariarc.json`, `.linariarc.yaml`, `.linariarc.yml`, `.linariarc.js`, `.linariarc.cjs`, `.config/linariarc`, `.config/linariarc.json`, `.config/linariarc.yaml`, `.config/linariarc.yml`, `.config/linariarc.js`, `.config/linariarc.cjs`, `linaria.config.js`, `linaria.config.cjs`];
4
- const explorerSync = cosmiconfigSync('linaria', {
3
+ const searchPlaces = [`.wyw-in-jsrc`, `.wyw-in-jsrc.json`, `.wyw-in-jsrc.yaml`, `.wyw-in-jsrc.yml`, `.wyw-in-jsrc.js`, `.wyw-in-jsrc.cjs`, `.config/wyw-in-jsrc`, `.config/wyw-in-jsrc.json`, `.config/wyw-in-jsrc.yaml`, `.config/wyw-in-jsrc.yml`, `.config/wyw-in-jsrc.js`, `.config/wyw-in-jsrc.cjs`, `wyw-in-js.config.js`, `wyw-in-js.config.cjs`];
4
+ const explorerSync = cosmiconfigSync('wyw-in-js', {
5
5
  searchPlaces
6
6
  });
7
7
  const cache = new WeakMap();
8
8
  const defaultOverrides = {};
9
9
  const nodeModulesRegExp = /[\\/]node_modules[\\/]/;
10
- export function loadLinariaOptions(overrides = defaultOverrides) {
10
+ export function loadWywOptions(overrides = defaultOverrides) {
11
11
  if (cache.has(overrides)) {
12
12
  return cache.get(overrides);
13
13
  }
@@ -46,7 +46,7 @@ export function loadLinariaOptions(overrides = defaultOverrides) {
46
46
  }
47
47
 
48
48
  // If a file contains `export` or `import` keywords, we assume it's an ES-module
49
- return /(?:^|\*\/|;)\s*(?:export|import)\s/m.test(code);
49
+ return /(?:^|\*\/|;|})\s*(?:export|import)[\s{]/m.test(code);
50
50
  },
51
51
  action: shaker
52
52
  }],
@@ -63,4 +63,4 @@ export function loadLinariaOptions(overrides = defaultOverrides) {
63
63
  cache.set(overrides, options);
64
64
  return options;
65
65
  }
66
- //# sourceMappingURL=loadLinariaOptions.js.map
66
+ //# sourceMappingURL=loadWywOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadWywOptions.js","names":["cosmiconfigSync","shaker","searchPlaces","explorerSync","cache","WeakMap","defaultOverrides","nodeModulesRegExp","loadWywOptions","overrides","has","get","configFile","ignore","rules","babelOptions","rest","result","undefined","load","search","defaultFeatures","dangerousCodeRemover","globalCache","happyDOM","softErrors","useBabelConfigs","options","displayName","evaluate","extensions","action","test","filename","code","highPriorityPlugins","config","features","set"],"sources":["../../../src/transform/helpers/loadWywOptions.ts"],"sourcesContent":["import { cosmiconfigSync } from 'cosmiconfig';\n\nimport type { FeatureFlags, StrictOptions } from '@wyw-in-js/shared';\n\nimport shaker from '../../shaker';\nimport type { PluginOptions } from '../../types';\n\nconst searchPlaces = [\n `.wyw-in-jsrc`,\n `.wyw-in-jsrc.json`,\n `.wyw-in-jsrc.yaml`,\n `.wyw-in-jsrc.yml`,\n `.wyw-in-jsrc.js`,\n `.wyw-in-jsrc.cjs`,\n `.config/wyw-in-jsrc`,\n `.config/wyw-in-jsrc.json`,\n `.config/wyw-in-jsrc.yaml`,\n `.config/wyw-in-jsrc.yml`,\n `.config/wyw-in-jsrc.js`,\n `.config/wyw-in-jsrc.cjs`,\n `wyw-in-js.config.js`,\n `wyw-in-js.config.cjs`,\n];\n\nconst explorerSync = cosmiconfigSync('wyw-in-js', { searchPlaces });\n\nexport type PartialOptions = Partial<Omit<PluginOptions, 'features'>> & {\n features?: Partial<FeatureFlags>;\n};\n\nconst cache = new WeakMap<Partial<PartialOptions>, StrictOptions>();\nconst defaultOverrides = {};\nconst nodeModulesRegExp = /[\\\\/]node_modules[\\\\/]/;\n\nexport function loadWywOptions(\n overrides: PartialOptions = defaultOverrides\n): StrictOptions {\n if (cache.has(overrides)) {\n return cache.get(overrides)!;\n }\n\n const { configFile, ignore, rules, babelOptions = {}, ...rest } = overrides;\n\n const result =\n // eslint-disable-next-line no-nested-ternary\n configFile === false\n ? undefined\n : configFile !== undefined\n ? explorerSync.load(configFile)\n : explorerSync.search();\n\n const defaultFeatures: FeatureFlags = {\n dangerousCodeRemover: true,\n globalCache: true,\n happyDOM: true,\n softErrors: false,\n useBabelConfigs: true,\n };\n\n const options: StrictOptions = {\n displayName: false,\n evaluate: true,\n extensions: ['.cjs', '.cts', '.js', '.jsx', '.mjs', '.mts', '.ts', '.tsx'],\n rules: rules ?? [\n {\n action: shaker,\n },\n {\n // The old `ignore` option is used as a default value for `ignore` rule.\n test: ignore ?? nodeModulesRegExp,\n action: 'ignore',\n },\n {\n // Do not ignore ES-modules\n test: (filename, code) => {\n if (!nodeModulesRegExp.test(filename)) {\n return false;\n }\n\n // If a file contains `export` or `import` keywords, we assume it's an ES-module\n return /(?:^|\\*\\/|;|})\\s*(?:export|import)[\\s{]/m.test(code);\n },\n action: shaker,\n },\n ],\n babelOptions,\n highPriorityPlugins: ['module-resolver'],\n ...(result ? result.config : {}),\n ...rest,\n features: {\n ...defaultFeatures,\n ...(result ? result.config.features : {}),\n ...rest.features,\n },\n };\n\n cache.set(overrides, options);\n\n return options;\n}\n"],"mappings":"AAAA,SAASA,eAAe,QAAQ,aAAa;AAI7C,OAAOC,MAAM,MAAM,cAAc;AAGjC,MAAMC,YAAY,GAAG,CAClB,cAAa,EACb,mBAAkB,EAClB,mBAAkB,EAClB,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;MACEiB,MAAM,EAAE9B;IACV,CAAC,EACD;MACE;MACA+B,IAAI,EAAEnB,MAAM,IAAIN,iBAAiB;MACjCwB,MAAM,EAAE;IACV,CAAC,EACD;MACE;MACAC,IAAI,EAAEA,CAACC,QAAQ,EAAEC,IAAI,KAAK;QACxB,IAAI,CAAC3B,iBAAiB,CAACyB,IAAI,CAACC,QAAQ,CAAC,EAAE;UACrC,OAAO,KAAK;QACd;;QAEA;QACA,OAAO,0CAA0C,CAACD,IAAI,CAACE,IAAI,CAAC;MAC9D,CAAC;MACDH,MAAM,EAAE9B;IACV,CAAC,CACF;IACDc,YAAY;IACZoB,mBAAmB,EAAE,CAAC,iBAAiB,CAAC;IACxC,IAAIlB,MAAM,GAAGA,MAAM,CAACmB,MAAM,GAAG,CAAC,CAAC,CAAC;IAChC,GAAGpB,IAAI;IACPqB,QAAQ,EAAE;MACR,GAAGhB,eAAe;MAClB,IAAIJ,MAAM,GAAGA,MAAM,CAACmB,MAAM,CAACC,QAAQ,GAAG,CAAC,CAAC,CAAC;MACzC,GAAGrB,IAAI,CAACqB;IACV;EACF,CAAC;EAEDjC,KAAK,CAACkC,GAAG,CAAC7B,SAAS,EAAEkB,OAAO,CAAC;EAE7B,OAAOA,OAAO;AAChB"}
package/esm/transform.js CHANGED
@@ -1,25 +1,26 @@
1
1
  /**
2
- * This file exposes transform function that:
2
+ * This file exposes sync and async transform functions that:
3
3
  * - parse the passed code to AST
4
- * - transforms the AST using Linaria babel preset ('./babel/index.js) and additional config defined in Linaria config file or passed to bundler configuration.
5
- * - runs generated CSS files through default of user-defined preprocessor
6
- * - generates source maps for CSS files
7
- * - return transformed code (without Linaria template literals), generated CSS, source maps and babel metadata from transform step.
4
+ * - builds a dependency graph for the file
5
+ * - shakes each dependency and removes unused code
6
+ * - runs generated code in a sandbox
7
+ * - collects artifacts
8
+ * - returns transformed code (without WYW template literals), generated CSS, source maps and babel metadata from transform step.
8
9
  */
9
10
 
10
11
  import { isFeatureEnabled } from '@wyw-in-js/shared';
12
+ import { loadWywOptions } from './transform/helpers/loadWywOptions';
11
13
  import { TransformCacheCollection } from './cache';
12
14
  import { Entrypoint } from './transform/Entrypoint';
13
15
  import { asyncActionRunner, syncActionRunner } from './transform/actions/actionRunner';
14
16
  import { baseHandlers } from './transform/generators';
15
17
  import { asyncResolveImports, syncResolveImports } from './transform/generators/resolveImports';
16
- import { loadLinariaOptions } from './transform/helpers/loadLinariaOptions';
17
18
  import { withDefaultServices } from './transform/helpers/withDefaultServices';
18
19
  export function transformSync(partialServices, originalCode, syncResolve, customHandlers = {}) {
19
20
  const {
20
21
  options
21
22
  } = partialServices;
22
- const pluginOptions = loadLinariaOptions(options.pluginOptions);
23
+ const pluginOptions = loadWywOptions(options.pluginOptions);
23
24
  const services = withDefaultServices({
24
25
  ...partialServices,
25
26
  options: {
@@ -31,7 +32,7 @@ export function transformSync(partialServices, originalCode, syncResolve, custom
31
32
  // If global cache is disabled, we need to create a new cache for each file
32
33
  services.cache = new TransformCacheCollection();
33
34
  }
34
- const entrypoint = Entrypoint.createRoot(services, options.filename, ['__linariaPreval'], originalCode);
35
+ const entrypoint = Entrypoint.createRoot(services, options.filename, ['__wywPreval'], originalCode);
35
36
  if (entrypoint.ignored) {
36
37
  return {
37
38
  code: originalCode,
@@ -66,7 +67,7 @@ export async function transform(partialServices, originalCode, asyncResolve, cus
66
67
  const {
67
68
  options
68
69
  } = partialServices;
69
- const pluginOptions = loadLinariaOptions(options.pluginOptions);
70
+ const pluginOptions = loadWywOptions(options.pluginOptions);
70
71
  const services = withDefaultServices({
71
72
  ...partialServices,
72
73
  options: {
@@ -87,7 +88,7 @@ export async function transform(partialServices, originalCode, asyncResolve, cus
87
88
  * but the "only" option has changed, the file will be re-processed using
88
89
  * the combined "only" option.
89
90
  */
90
- const entrypoint = Entrypoint.createRoot(services, options.filename, ['__linariaPreval'], originalCode);
91
+ const entrypoint = Entrypoint.createRoot(services, options.filename, ['__wywPreval'], originalCode);
91
92
  if (entrypoint.ignored) {
92
93
  return {
93
94
  code: originalCode,