@embroider/macros 1.21.2 → 1.21.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/README.md +1 -1
  2. package/package.json +2 -2
  3. package/src/babel/app-ember-satisfies.d.ts +5 -0
  4. package/src/babel/app-ember-satisfies.js +38 -0
  5. package/src/babel/app-ember-satisfies.js.map +1 -0
  6. package/src/babel/dependency-satisfies.d.ts +5 -0
  7. package/src/babel/dependency-satisfies.js +38 -0
  8. package/src/babel/dependency-satisfies.js.map +1 -0
  9. package/src/babel/each.d.ts +14 -0
  10. package/src/babel/each.js +55 -0
  11. package/src/babel/each.js.map +1 -0
  12. package/src/babel/error.d.ts +3 -0
  13. package/src/babel/error.js +21 -0
  14. package/src/babel/error.js.map +1 -0
  15. package/src/babel/evaluate-json.d.ts +36 -0
  16. package/src/babel/evaluate-json.js +429 -0
  17. package/src/babel/evaluate-json.js.map +1 -0
  18. package/src/babel/fail-build.d.ts +5 -0
  19. package/src/babel/fail-build.js +36 -0
  20. package/src/babel/fail-build.js.map +1 -0
  21. package/src/babel/get-config.d.ts +9 -0
  22. package/src/babel/get-config.js +107 -0
  23. package/src/babel/get-config.js.map +1 -0
  24. package/src/babel/import-sync-pattern.d.ts +22 -0
  25. package/src/babel/import-sync-pattern.js +151 -0
  26. package/src/babel/import-sync-pattern.js.map +1 -0
  27. package/src/babel/macro-condition.d.ts +12 -0
  28. package/src/babel/macro-condition.js +76 -0
  29. package/src/babel/macro-condition.js.map +1 -0
  30. package/src/babel/macros-babel-plugin.d.ts +3 -0
  31. package/src/babel/macros-babel-plugin.js +312 -0
  32. package/src/babel/macros-babel-plugin.js.map +1 -0
  33. package/src/babel/module-exists.d.ts +5 -0
  34. package/src/babel/module-exists.js +30 -0
  35. package/src/babel/module-exists.js.map +1 -0
  36. package/src/babel/state.d.ts +34 -0
  37. package/src/babel/state.js +64 -0
  38. package/src/babel/state.js.map +1 -0
  39. package/src/babel.d.ts +47 -0
  40. package/src/babel.js +36 -0
  41. package/src/babel.js.map +1 -0
  42. package/src/ember-addon-main.d.ts +9 -0
  43. package/src/ember-addon-main.js +112 -0
  44. package/src/ember-addon-main.js.map +1 -0
  45. package/src/glimmer/app-ember-satisfies.d.ts +3 -0
  46. package/src/glimmer/app-ember-satisfies.js +32 -0
  47. package/src/glimmer/app-ember-satisfies.js.map +1 -0
  48. package/src/glimmer/ast-transform.d.ts +133 -0
  49. package/src/glimmer/ast-transform.js +240 -0
  50. package/src/glimmer/ast-transform.js.map +1 -0
  51. package/src/glimmer/dependency-satisfies.d.ts +3 -0
  52. package/src/glimmer/dependency-satisfies.js +37 -0
  53. package/src/glimmer/dependency-satisfies.js.map +1 -0
  54. package/src/glimmer/evaluate.d.ts +7 -0
  55. package/src/glimmer/evaluate.js +16 -0
  56. package/src/glimmer/evaluate.js.map +1 -0
  57. package/src/glimmer/fail-build.d.ts +2 -0
  58. package/src/glimmer/fail-build.js +22 -0
  59. package/src/glimmer/fail-build.js.map +1 -0
  60. package/src/glimmer/get-config.d.ts +5 -0
  61. package/src/glimmer/get-config.js +38 -0
  62. package/src/glimmer/get-config.js.map +1 -0
  63. package/src/glimmer/literal.d.ts +2 -0
  64. package/src/glimmer/literal.js +28 -0
  65. package/src/glimmer/literal.js.map +1 -0
  66. package/src/glimmer/macro-condition.d.ts +7 -0
  67. package/src/glimmer/macro-condition.js +119 -0
  68. package/src/glimmer/macro-condition.js.map +1 -0
  69. package/src/glimmer/macro-maybe-attrs.d.ts +2 -0
  70. package/src/glimmer/macro-maybe-attrs.js +31 -0
  71. package/src/glimmer/macro-maybe-attrs.js.map +1 -0
  72. package/src/index.d.ts +59 -0
  73. package/src/index.js +80 -0
  74. package/src/index.js.map +1 -0
  75. package/src/macros-config.d.ts +52 -0
  76. package/src/macros-config.js +394 -0
  77. package/src/macros-config.js.map +1 -0
  78. package/src/node.d.ts +5 -0
  79. package/src/node.js +21 -0
  80. package/src/node.js.map +1 -0
@@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0DAA0D;gBAC1D,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;YAC1E,CAAC;QACH,CAAC;KACF,CAAC;IAEF,IAAK,OAAe,CAAC,KAAK,CAAC,wBAAwB,EAAE,CAAC;QACpD,0EAA0E;QAC1E,4EAA4E;QAC5E,wCAAwC;QACvC,OAAe,CAAC,wBAAwB,GAAG;YAC1C,KAAK,CAAC,IAA0C,EAAE,KAAY;gBAC5D,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;oBACvC,IAAI,MAAM,GAAG,IAAI,yBAAS,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;oBACrD,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;wBACrB,IAAI,CAAC,WAAW,CAAC,IAAA,6BAAa,EAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;oBACzD,CAAC;gBACH,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,CAAC;AACrB,CAAC","sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport type { types as t } from '@babel/core';\nimport type State from './state';\nimport { initState } from './state';\nimport type { Mode as GetConfigMode } from './get-config';\nimport { inlineRuntimeConfig, insertConfig } from './get-config';\nimport macroCondition, { identifyMacroConditionPath } from './macro-condition';\nimport { isEachPath, insertEach } from './each';\n\nimport error from './error';\nimport failBuild from './fail-build';\nimport { Evaluator, buildLiterals } from './evaluate-json';\nimport type * as Babel from '@babel/core';\nimport { existsSync, readdirSync } from 'fs';\nimport {\n entryKey,\n lookupExpression,\n parseSpecifier,\n patternMatcher,\n patternParts,\n relativeSpecifier,\n} from './import-sync-pattern';\nimport { resolve, dirname, join } from 'path';\n\nexport default function main(context: typeof Babel): unknown {\n let t = context.types;\n let visitor = {\n Program: {\n enter(path: NodePath<t.Program>, state: State) {\n initState(context, path, state);\n },\n exit(_: NodePath<t.Program>, state: State) {\n // @embroider/macros itself has no runtime behaviors and should always be removed\n state.importUtil.removeAllImports('@embroider/macros');\n for (let handler of state.jobs) {\n handler();\n }\n },\n },\n 'IfStatement|ConditionalExpression|LogicalExpression': {\n enter(path: NodePath<t.IfStatement | t.ConditionalExpression | t.LogicalExpression>, state: State) {\n let found = identifyMacroConditionPath(path);\n if (found) {\n state.calledIdentifiers.add(found.callExpression.get('callee').node);\n macroCondition(found, state, context);\n }\n },\n },\n ForOfStatement: {\n enter(path: NodePath<t.ForOfStatement>, state: State) {\n if (isEachPath(path)) {\n state.calledIdentifiers.add(path.get('right').get('callee').node);\n insertEach(path, state, context);\n }\n },\n },\n FunctionDeclaration: {\n enter(path: NodePath<t.FunctionDeclaration>, state: State) {\n let id = path.get('id');\n if (id.isIdentifier() && id.node.name === 'initializeRuntimeMacrosConfig' && state.opts.mode === 'run-time') {\n let pkg = state.owningPackage();\n if (pkg && pkg.name === '@embroider/macros') {\n inlineRuntimeConfig(path, state, context);\n }\n }\n },\n },\n CallExpression: {\n enter(path: NodePath<t.CallExpression>, state: State) {\n let callee = path.get('callee');\n if (!callee.isIdentifier()) {\n return;\n }\n\n // failBuild is implemented for side-effect, not value, so it's not\n // handled by evaluateMacroCall.\n if (callee.referencesImport('@embroider/macros', 'failBuild')) {\n state.calledIdentifiers.add(callee.node);\n failBuild(path, state);\n return;\n }\n\n if (callee.referencesImport('@embroider/macros', 'importSync')) {\n // we handle importSync in the exit hook\n return;\n }\n\n // getOwnConfig/getGlobalConfig/getConfig needs special handling, so\n // even though it also emits values via evaluateMacroCall when they're\n // needed recursively by other macros, it has its own insertion-handling\n // code that we invoke here.\n //\n // The things that are special include:\n // - automatic collapsing of chained properties, etc\n // - these macros have runtime implementations sometimes, which changes\n // how we rewrite them\n let mode: GetConfigMode | false = callee.referencesImport('@embroider/macros', 'getOwnConfig')\n ? 'own'\n : callee.referencesImport('@embroider/macros', 'getGlobalConfig')\n ? 'getGlobalConfig'\n : callee.referencesImport('@embroider/macros', 'getConfig')\n ? 'package'\n : false;\n if (mode) {\n state.calledIdentifiers.add(callee.node);\n insertConfig(path, state, mode, context);\n return;\n }\n\n // isTesting can have a runtime implementation. At compile time it\n // instead falls through to evaluateMacroCall.\n if (callee.referencesImport('@embroider/macros', 'isTesting') && state.opts.mode === 'run-time') {\n state.calledIdentifiers.add(callee.node);\n callee.replaceWith(state.importUtil.import(callee, state.pathToOurAddon('runtime'), 'isTesting'));\n return;\n }\n\n if (callee.referencesImport('@embroider/macros', 'setTesting')) {\n state.calledIdentifiers.add(callee.node);\n\n if (state.opts.mode === 'run-time') {\n callee.replaceWith(state.importUtil.import(callee, state.pathToOurAddon('runtime'), 'setTesting'));\n } else {\n let args = path.get('arguments');\n if (args.length === 0) {\n throw error(path, `setTesting() requires a boolean argument`);\n }\n\n let arg = args[0];\n let evaluator = new Evaluator({ state });\n let result = evaluator.evaluate(arg);\n\n if (!result.confident) {\n throw error(\n arg,\n `setTesting() can only be called with a statically analyzable value in compile-time mode. The argument must be a literal boolean or other macro that can resolves to a boolean at compile-time.`\n );\n }\n\n let macrosConfig = (state.opts.globalConfig['@embroider/macros'] as any) || {};\n let currentIsTesting = Boolean(macrosConfig.isTesting);\n let newIsTesting = Boolean(result.value);\n\n if (currentIsTesting !== newIsTesting) {\n throw error(\n path,\n `setTesting(${newIsTesting}) cannot change the testing state in compile-time mode. The current global config has isTesting=${currentIsTesting}. ` +\n `setTesting() calls are compiled away at build time, so they cannot change the testing state. ` +\n `If you need to change the testing state at runtime, use runtime mode instead.`\n );\n }\n\n path.remove();\n }\n return;\n }\n\n let result = new Evaluator({ state }).evaluateMacroCall(path);\n if (result.confident) {\n state.calledIdentifiers.add(callee.node);\n path.replaceWith(buildLiterals(result.value, context));\n }\n },\n exit(path: NodePath<t.CallExpression>, state: State) {\n let callee = path.get('callee');\n if (!callee.isIdentifier()) {\n return;\n }\n // importSync doesn't evaluate to a static value, so it's implemented\n // directly here, not in evaluateMacroCall.\n // We intentionally do this on exit here, to allow other transforms to handle importSync before we do\n // For example ember-auto-import needs to do some custom transforms to enable use of dynamic template strings,\n // so its babel plugin needs to see and handle the importSync call first!\n if (callee.referencesImport('@embroider/macros', 'importSync')) {\n if (state.opts.importSyncImplementation === 'eager') {\n let specifier = path.node.arguments[0];\n let target: string | undefined;\n if (specifier?.type === 'StringLiteral') {\n target = specifier.value;\n } else {\n let parts = specifier ? patternParts(t, specifier) : undefined;\n if (parts && parts.length > 0 && parts.every(part => part.type === 'static')) {\n // a template literal that has no interpolations at all is just\n // a string, so treat it like one\n target = parts.map(part => (part.type === 'static' ? part.value : '')).join('');\n } else {\n let parsed = parts ? parseSpecifier(parts) : undefined;\n if (!parsed) {\n throw new Error(\n `importSync eager mode only supports dynamic paths which are relative, must start with a '.', had ${specifier?.type}`\n );\n }\n const { dir, pattern } = parsed;\n const resolvedPath = resolve(dirname((state as any).filename), dir);\n let entries: string[] = [];\n if (existsSync(resolvedPath)) {\n entries = readdirSync(resolvedPath).filter(e => !e.startsWith('.'));\n }\n const matches = patternMatcher(pattern);\n const seen = new Set<string>();\n const properties: t.ObjectProperty[] = [];\n for (const entry of entries) {\n const key = entryKey(entry);\n // entries that the pattern could never select would just bloat\n // the bundle, and files that differ only by extension collapse\n // to the same key (and the same extension-less import)\n if (!matches(key) || seen.has(key)) {\n continue;\n }\n seen.add(key);\n const id = t.callExpression(\n state.importUtil.import(path, state.pathToOurAddon('es-compat2'), 'default', 'esc'),\n [state.importUtil.import(path, relativeSpecifier(join(dir, key)), '*')]\n );\n properties.push(t.objectProperty(t.stringLiteral(key), id));\n }\n const memberExpr = t.memberExpression(\n t.objectExpression(properties),\n lookupExpression(t, pattern),\n true\n );\n path.replaceWith(memberExpr);\n state.calledIdentifiers.add(callee.node);\n return;\n }\n }\n path.replaceWith(\n t.callExpression(state.importUtil.import(path, state.pathToOurAddon('es-compat2'), 'default', 'esc'), [\n state.importUtil.import(path, target, '*'),\n ])\n );\n state.calledIdentifiers.add(callee.node);\n return;\n } else {\n if (path.scope.hasBinding('require')) {\n path.scope.rename('require');\n }\n let r = t.identifier('require');\n state.generatedRequires.add(r);\n path.replaceWith(\n t.callExpression(state.importUtil.import(path, state.pathToOurAddon('es-compat2'), 'default', 'esc'), [\n t.callExpression(r, path.node.arguments),\n ])\n );\n }\n }\n },\n },\n ReferencedIdentifier(path: NodePath<t.Identifier>, state: State) {\n for (let candidate of [\n 'dependencySatisfies',\n 'appEmberSatisfies',\n 'moduleExists',\n 'getConfig',\n 'getOwnConfig',\n 'failBuild',\n // we cannot check importSync, as the babel transform runs on exit, so *after* this check\n // 'importSync',\n 'isDevelopingApp',\n 'isDevelopingThisPackage',\n 'isTesting',\n 'setTesting',\n ]) {\n if (path.referencesImport('@embroider/macros', candidate) && !state.calledIdentifiers.has(path.node)) {\n throw error(path, `You can only use ${candidate} as a function call`);\n }\n }\n\n if (path.referencesImport('@embroider/macros', 'macroCondition') && !state.calledIdentifiers.has(path.node)) {\n throw error(\n path,\n `macroCondition can only be used as the predicate of an if statement, ternary expression, or && / || logical expression`\n );\n }\n\n if (path.referencesImport('@embroider/macros', 'each') && !state.calledIdentifiers.has(path.node)) {\n throw error(\n path,\n `the each() macro can only be used within a for ... of statement, like: for (let x of each(thing)){}`\n );\n }\n\n if (state.opts.owningPackageRoot) {\n // there is only an owningPackageRoot when we are running inside a\n // classic ember-cli build. In the embroider stage3 build, there is no\n // owning package root because we're compiling *all* packages\n // simultaneously.\n //\n // given that we're inside classic ember-cli, stop here without trying\n // to rewrite bare `require`. It's not needed, because both our\n // `importSync` and any user-written bare `require` can both mean the\n // same thing: runtime AMD `require`.\n return;\n }\n\n if (\n path.node.name === 'require' &&\n !state.generatedRequires.has(path.node) &&\n !path.scope.hasBinding('require') &&\n state.owningPackage().isEmberAddon()\n ) {\n // Our importSync macro has been compiled to `require`. But we want to\n // distinguish that from any pre-existing, user-written `require` in an\n // Ember addon, which should retain its *runtime* meaning.\n path.replaceWith(t.memberExpression(t.identifier('window'), path.node));\n }\n },\n };\n\n if ((context as any).types.OptionalMemberExpression) {\n // our getConfig and getOwnConfig macros are supposed to be able to absorb\n // optional chaining. To make that work we need to see the optional chaining\n // before preset-env compiles them away.\n (visitor as any).OptionalMemberExpression = {\n enter(path: NodePath<t.OptionalMemberExpression>, state: State) {\n if (state.opts.mode === 'compile-time') {\n let result = new Evaluator({ state }).evaluate(path);\n if (result.confident) {\n path.replaceWith(buildLiterals(result.value, context));\n }\n }\n },\n };\n }\n\n return { visitor };\n}\n"]}
@@ -0,0 +1,5 @@
1
+ import type { NodePath } from '@babel/traverse';
2
+ import type { types as t } from '@babel/core';
3
+ import type State from './state';
4
+ export default function moduleExists(path: NodePath<t.CallExpression>, state: State): boolean;
5
+ //# sourceMappingURL=module-exists.d.ts.map
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = moduleExists;
7
+ const error_1 = __importDefault(require("./error"));
8
+ const evaluate_json_1 = require("./evaluate-json");
9
+ const resolve_1 = __importDefault(require("resolve"));
10
+ const path_1 = require("path");
11
+ function moduleExists(path, state) {
12
+ if (path.node.arguments.length !== 1) {
13
+ throw (0, error_1.default)(path, `moduleExists takes exactly one argument, you passed ${path.node.arguments.length}`);
14
+ }
15
+ let [moduleSpecifier] = path.node.arguments;
16
+ if (moduleSpecifier.type !== 'StringLiteral') {
17
+ throw (0, error_1.default)((0, evaluate_json_1.assertArray)(path.get('arguments'))[0], `the first argument to moduleExists must be a string literal`);
18
+ }
19
+ try {
20
+ resolve_1.default.sync(moduleSpecifier.value, { basedir: (0, path_1.dirname)(state.sourceFile) });
21
+ return true;
22
+ }
23
+ catch (err) {
24
+ if (err.code !== 'MODULE_NOT_FOUND') {
25
+ throw err;
26
+ }
27
+ return false;
28
+ }
29
+ }
30
+ //# sourceMappingURL=module-exists.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-exists.js","sourceRoot":"","sources":["module-exists.ts"],"names":[],"mappings":";;;;;AAQA,+BAiBC;AAtBD,oDAA4B;AAC5B,mDAA8C;AAC9C,sDAA8B;AAC9B,+BAA+B;AAE/B,SAAwB,YAAY,CAAC,IAAgC,EAAE,KAAY;IACjF,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrC,MAAM,IAAA,eAAK,EAAC,IAAI,EAAE,uDAAuD,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;IACzG,CAAC;IACD,IAAI,CAAC,eAAe,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC;IAC5C,IAAI,eAAe,CAAC,IAAI,KAAK,eAAe,EAAE,CAAC;QAC7C,MAAM,IAAA,eAAK,EAAC,IAAA,2BAAW,EAAC,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,6DAA6D,CAAC,CAAC;IACpH,CAAC;IACD,IAAI,CAAC;QACH,iBAAO,CAAC,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,IAAA,cAAO,EAAC,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;QAC5E,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,CAAC,IAAI,KAAK,kBAAkB,EAAE,CAAC;YACpC,MAAM,GAAG,CAAC;QACZ,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC","sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport type { types as t } from '@babel/core';\nimport type State from './state';\nimport error from './error';\nimport { assertArray } from './evaluate-json';\nimport resolve from 'resolve';\nimport { dirname } from 'path';\n\nexport default function moduleExists(path: NodePath<t.CallExpression>, state: State): boolean {\n if (path.node.arguments.length !== 1) {\n throw error(path, `moduleExists takes exactly one argument, you passed ${path.node.arguments.length}`);\n }\n let [moduleSpecifier] = path.node.arguments;\n if (moduleSpecifier.type !== 'StringLiteral') {\n throw error(assertArray(path.get('arguments'))[0], `the first argument to moduleExists must be a string literal`);\n }\n try {\n resolve.sync(moduleSpecifier.value, { basedir: dirname(state.sourceFile) });\n return true;\n } catch (err) {\n if (err.code !== 'MODULE_NOT_FOUND') {\n throw err;\n }\n return false;\n }\n}\n"]}
@@ -0,0 +1,34 @@
1
+ import type { NodePath, Node } from '@babel/traverse';
2
+ import type { Package } from '@embroider/shared-internals';
3
+ import { RewrittenPackageCache } from '@embroider/shared-internals';
4
+ import { ImportUtil } from 'babel-import-util';
5
+ import type * as Babel from '@babel/core';
6
+ export default interface State {
7
+ importUtil: ImportUtil;
8
+ generatedRequires: Set<Node>;
9
+ removed: Set<Node>;
10
+ calledIdentifiers: Set<Node>;
11
+ jobs: (() => void)[];
12
+ packageCache: RewrittenPackageCache;
13
+ sourceFile: string;
14
+ pathToOurAddon(moduleName: string): string;
15
+ owningPackage(): Package;
16
+ originalOwningPackage(): Package;
17
+ cloneDeep(node: Node): Node;
18
+ opts: {
19
+ userConfigs: {
20
+ [pkgRoot: string]: unknown;
21
+ };
22
+ globalConfig: {
23
+ [key: string]: unknown;
24
+ };
25
+ owningPackageRoot: string | undefined;
26
+ isDevelopingPackageRoots: string[];
27
+ appPackageRoot: string;
28
+ embroiderMacrosConfigMarker: true;
29
+ importSyncImplementation: 'cjs' | 'eager';
30
+ mode: 'compile-time' | 'run-time';
31
+ };
32
+ }
33
+ export declare function initState(t: typeof Babel, path: NodePath<Babel.types.Program>, state: State): void;
34
+ //# sourceMappingURL=state.d.ts.map
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.initState = initState;
7
+ const cloneDeepWith_1 = __importDefault(require("lodash/cloneDeepWith"));
8
+ const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
9
+ const path_1 = require("path");
10
+ const shared_internals_1 = require("@embroider/shared-internals");
11
+ const babel_import_util_1 = require("babel-import-util");
12
+ function initState(t, path, state) {
13
+ state.importUtil = new babel_import_util_1.ImportUtil(t, path);
14
+ state.generatedRequires = new Set();
15
+ state.jobs = [];
16
+ state.removed = new Set();
17
+ state.calledIdentifiers = new Set();
18
+ state.packageCache = shared_internals_1.RewrittenPackageCache.shared('embroider', state.opts.appPackageRoot);
19
+ state.sourceFile = state.opts.owningPackageRoot || (0, shared_internals_1.cleanUrl)(path.hub.file.opts.filename);
20
+ state.pathToOurAddon = pathToAddon;
21
+ state.owningPackage = owningPackage;
22
+ state.originalOwningPackage = originalOwningPackage;
23
+ state.cloneDeep = cloneDeep;
24
+ }
25
+ const runtimeAddonPath = (0, path_1.resolve)((0, path_1.join)(__dirname, '..', 'addon'));
26
+ function pathToAddon(moduleName) {
27
+ if (!this.opts.owningPackageRoot) {
28
+ // running inside embroider, so make a relative path to the module
29
+ return (0, shared_internals_1.explicitRelative)((0, path_1.dirname)(this.sourceFile), (0, path_1.join)(runtimeAddonPath, moduleName));
30
+ }
31
+ else {
32
+ // running inside a classic build, so use a classic-compatible runtime
33
+ // specifier.
34
+ //
35
+ // CAUTION: the module we're pointing at here gets merged between all
36
+ // present versions of @embroider/macros, and one will win. So if you are
37
+ // introducing incompatible changes to its API, you need to change this name
38
+ // (by tacking on a version number, etc) and rename the corresponding file
39
+ // in ../addon.
40
+ return `@embroider/macros/${moduleName}`;
41
+ }
42
+ }
43
+ function owningPackage() {
44
+ let pkg = this.packageCache.ownerOfFile(this.sourceFile);
45
+ if (!pkg) {
46
+ throw new Error(`unable to determine which npm package owns the file ${this.sourceFile}`);
47
+ }
48
+ return pkg;
49
+ }
50
+ function originalOwningPackage() {
51
+ let pkg = this.owningPackage();
52
+ return this.packageCache.original(pkg);
53
+ }
54
+ function cloneDeep(node) {
55
+ let state = this;
56
+ return (0, cloneDeepWith_1.default)(node, function (value) {
57
+ if (state.generatedRequires.has(value)) {
58
+ let cloned = (0, cloneDeep_1.default)(value);
59
+ state.generatedRequires.add(cloned);
60
+ return cloned;
61
+ }
62
+ });
63
+ }
64
+ //# sourceMappingURL=state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.js","sourceRoot":"","sources":["state.ts"],"names":[],"mappings":";;;;;AAqDA,8BAYC;AAhED,yEAAiD;AACjD,iEAA+C;AAC/C,+BAA8C;AAE9C,kEAAgG;AAChG,yDAA+C;AA+C/C,SAAgB,SAAS,CAAC,CAAe,EAAE,IAAmC,EAAE,KAAY;IAC1F,KAAK,CAAC,UAAU,GAAG,IAAI,8BAAU,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IAC3C,KAAK,CAAC,iBAAiB,GAAG,IAAI,GAAG,EAAE,CAAC;IACpC,KAAK,CAAC,IAAI,GAAG,EAAE,CAAC;IAChB,KAAK,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;IAC1B,KAAK,CAAC,iBAAiB,GAAG,IAAI,GAAG,EAAE,CAAC;IACpC,KAAK,CAAC,YAAY,GAAG,wCAAqB,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAC1F,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,iBAAiB,IAAI,IAAA,2BAAQ,EAAE,IAAI,CAAC,GAAW,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAClG,KAAK,CAAC,cAAc,GAAG,WAAW,CAAC;IACnC,KAAK,CAAC,aAAa,GAAG,aAAa,CAAC;IACpC,KAAK,CAAC,qBAAqB,GAAG,qBAAqB,CAAC;IACpD,KAAK,CAAC,SAAS,GA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AC,KAAK,CAAC,CAAC;YACpC,KAAK,CAAC,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACpC,OAAO,MAAM,CAAC;QAChB,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { NodePath, Node } from '@babel/traverse';\nimport cloneDeepWith from 'lodash/cloneDeepWith';\nimport lodashCloneDeep from 'lodash/cloneDeep';\nimport { join, dirname, resolve } from 'path';\nimport type { Package } from '@embroider/shared-internals';\nimport { cleanUrl, explicitRelative, RewrittenPackageCache } from '@embroider/shared-internals';\nimport { ImportUtil } from 'babel-import-util';\nimport type * as Babel from '@babel/core';\n\nexport default interface State {\n importUtil: ImportUtil;\n generatedRequires: Set<Node>;\n removed: Set<Node>;\n calledIdentifiers: Set<Node>;\n jobs: (() => void)[];\n packageCache: RewrittenPackageCache;\n sourceFile: string;\n pathToOurAddon(moduleName: string): string;\n owningPackage(): Package;\n originalOwningPackage(): Package;\n cloneDeep(node: Node): Node;\n\n opts: {\n userConfigs: {\n [pkgRoot: string]: unknown;\n };\n globalConfig: {\n [key: string]: unknown;\n };\n // we set this when we're running inside classic ember-cli, because in that\n // case we don't have finer-grained info available about where the files\n // we're processing are globally located. When running in embroider, we\n // don't set this, because each file is visible at its full\n // globally-relevant path.\n owningPackageRoot: string | undefined;\n\n // list of packages that are under active development, represented by the\n // path to their package root directory\n isDevelopingPackageRoots: string[];\n\n // the package root directory of the app. Needed so that we can get\n // consistent answers to `isDevelopingApp` and `isDeveopingThisPackage`, as\n // well as consistent handling of Package devDependencies vs dependencies.\n appPackageRoot: string;\n\n embroiderMacrosConfigMarker: true;\n\n importSyncImplementation: 'cjs' | 'eager';\n\n mode: 'compile-time' | 'run-time';\n };\n}\n\nexport function initState(t: typeof Babel, path: NodePath<Babel.types.Program>, state: State) {\n state.importUtil = new ImportUtil(t, path);\n state.generatedRequires = new Set();\n state.jobs = [];\n state.removed = new Set();\n state.calledIdentifiers = new Set();\n state.packageCache = RewrittenPackageCache.shared('embroider', state.opts.appPackageRoot);\n state.sourceFile = state.opts.owningPackageRoot || cleanUrl((path.hub as any).file.opts.filename);\n state.pathToOurAddon = pathToAddon;\n state.owningPackage = owningPackage;\n state.originalOwningPackage = originalOwningPackage;\n state.cloneDeep = cloneDeep;\n}\n\nconst runtimeAddonPath = resolve(join(__dirname, '..', 'addon'));\n\nfunction pathToAddon(this: State, moduleName: string): string {\n if (!this.opts.owningPackageRoot) {\n // running inside embroider, so make a relative path to the module\n return explicitRelative(dirname(this.sourceFile), join(runtimeAddonPath, moduleName));\n } else {\n // running inside a classic build, so use a classic-compatible runtime\n // specifier.\n //\n // CAUTION: the module we're pointing at here gets merged between all\n // present versions of @embroider/macros, and one will win. So if you are\n // introducing incompatible changes to its API, you need to change this name\n // (by tacking on a version number, etc) and rename the corresponding file\n // in ../addon.\n return `@embroider/macros/${moduleName}`;\n }\n}\n\nfunction owningPackage(this: State): Package {\n let pkg = this.packageCache.ownerOfFile(this.sourceFile);\n if (!pkg) {\n throw new Error(`unable to determine which npm package owns the file ${this.sourceFile}`);\n }\n return pkg;\n}\n\nfunction originalOwningPackage(this: State): Package {\n let pkg = this.owningPackage();\n return this.packageCache.original(pkg);\n}\n\nfunction cloneDeep(this: State, node: Node): Node {\n let state = this;\n return cloneDeepWith(node, function (value: any) {\n if (state.generatedRequires.has(value)) {\n let cloned = lodashCloneDeep(value);\n state.generatedRequires.add(cloned);\n return cloned;\n }\n });\n}\n"]}
package/src/babel.d.ts ADDED
@@ -0,0 +1,47 @@
1
+ import MacrosConfig from './macros-config';
2
+ export interface Options {
3
+ /**
4
+ * How you configure your own package / app
5
+ */
6
+ setOwnConfig?: object;
7
+ /**
8
+ * This is how you can optionally send configuration into
9
+ * your dependencies, if those dependencies choose to use
10
+ * @embroider/macros configs.
11
+ *
12
+ * @example
13
+ * ```js
14
+ * setConfig: {
15
+ * 'some-dependency': {
16
+ * // config for some-dependency
17
+ * }
18
+ * }
19
+ * ```
20
+ */
21
+ setConfig?: Record<string, object>;
22
+ /**
23
+ * Callback for further manipulation of the macros' configuration instance.
24
+ *
25
+ * Useful for libraries to provide their own config with defaults shared between sub-dependencies of those libraries.
26
+ */
27
+ configure?: (macrosInstance: MacrosConfig) => void;
28
+ /**
29
+ * Override the default directory used for the MacrosConfig
30
+ *
31
+ * defaults to the CWD, via process.cwd()
32
+ */
33
+ dir?: string;
34
+ }
35
+ interface ConfiguredMacros {
36
+ /**
37
+ * Array of plugins to add to the babel config plugins array
38
+ */
39
+ babelMacros: ReturnType<MacrosConfig['babelPluginConfig']>;
40
+ /**
41
+ * Array of template transforms to pass to the transforms array of the babel-plugin-ember-template-compilation babel plugin
42
+ */
43
+ templateMacros: ReturnType<(typeof MacrosConfig)['transforms']>['plugins'];
44
+ }
45
+ export declare function buildMacros(options?: Options): ConfiguredMacros;
46
+ export {};
47
+ //# sourceMappingURL=babel.d.ts.map
package/src/babel.js ADDED
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.buildMacros = buildMacros;
7
+ const macros_config_1 = __importDefault(require("./macros-config"));
8
+ function buildMacros(options = {}) {
9
+ let root = options.dir || process.cwd();
10
+ let macros = macros_config_1.default.for({}, root);
11
+ let transforms = macros_config_1.default.transforms();
12
+ transforms.setConfig(macros);
13
+ let { setOwnConfig, setConfig, configure } = options;
14
+ if (setOwnConfig) {
15
+ macros.setOwnConfig(root, setOwnConfig);
16
+ }
17
+ if (setConfig) {
18
+ for (let [packageName, config] of Object.entries(setConfig)) {
19
+ macros.setConfig(root, packageName, config);
20
+ }
21
+ }
22
+ configure === null || configure === void 0 ? void 0 : configure(macros);
23
+ if (process.env.NODE_ENV === 'development') {
24
+ macros.enablePackageDevelopment(process.cwd());
25
+ macros.enableRuntimeMode();
26
+ }
27
+ // `buildMacros` is only ever called under Embroider 4.x, where the eager
28
+ // implementation is mandatory.
29
+ macros.importSyncImplementation = 'eager';
30
+ macros.finalize();
31
+ return {
32
+ babelMacros: macros.babelPluginConfig(),
33
+ templateMacros: transforms.plugins,
34
+ };
35
+ }
36
+ //# sourceMappingURL=babel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babel.js","sourceRoot":"","sources":["babel.ts"],"names":[],"mappings":";;;;;AAiDA,kCAqCC;AAtFD,oEAA2C;AAiD3C,SAAgB,WAAW,CAAC,UAAmB,EAAE;IAC/C,IAAI,IAAI,GAAG,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IACxC,IAAI,MAAM,GAAG,uBAAY,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IAExC,IAAI,UAAU,GAAG,uBAAY,CAAC,UAAU,EAAE,CAAC;IAE3C,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAE7B,IAAI,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAErD,IAAI,YAAY,EAAE,CAAC;QACjB,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IAC1C,CAAC;IAED,IAAI,SAAS,EAAE,CAAC;QACd,KAAK,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;YAC5D,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,WAAW,EAAE,MAAgB,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;IAED,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAG,MAAM,CAAC,CAAC;IAEpB,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,EAAE,CAAC;QAC3C,MAAM,CAAC,wBAAwB,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;QAC/C,MAAM,CAAC,iBAAiB,EAAE,CAAC;IAC7B,CAAC;IAED,yEAAyE;IACzE,+BAA+B;IAC/B,MAAM,CAAC,wBAAwB,GAAG,OAAO,CAAC;IAE1C,MAAM,CAAC,QAAQ,EAAE,CAAC;IAElB,OAAO;QACL,WAAW,EAAE,MAAM,CAAC,iBAAiB,EAAE;QACvC,cAAc,EAAE,UAAU,CAAC,OAAO;KACnC,CAAC;AACJ,CAAC","sourcesContent":["import MacrosConfig from './macros-config';\n\nexport interface Options {\n /**\n * How you configure your own package / app\n */\n setOwnConfig?: object;\n /**\n * This is how you can optionally send configuration into\n * your dependencies, if those dependencies choose to use\n * @embroider/macros configs.\n *\n * @example\n * ```js\n * setConfig: {\n * 'some-dependency': {\n * // config for some-dependency\n * }\n * }\n * ```\n */\n setConfig?: Record<string, object>;\n\n /**\n * Callback for further manipulation of the macros' configuration instance.\n *\n * Useful for libraries to provide their own config with defaults shared between sub-dependencies of those libraries.\n */\n configure?: (macrosInstance: MacrosConfig) => void;\n\n /**\n * Override the default directory used for the MacrosConfig\n *\n * defaults to the CWD, via process.cwd()\n */\n dir?: string;\n}\n\ninterface ConfiguredMacros {\n /**\n * Array of plugins to add to the babel config plugins array\n */\n babelMacros: ReturnType<MacrosConfig['babelPluginConfig']>;\n /**\n * Array of template transforms to pass to the transforms array of the babel-plugin-ember-template-compilation babel plugin\n */\n templateMacros: ReturnType<(typeof MacrosConfig)['transforms']>['plugins'];\n}\n\nexport function buildMacros(options: Options = {}): ConfiguredMacros {\n let root = options.dir || process.cwd();\n let macros = MacrosConfig.for({}, root);\n\n let transforms = MacrosConfig.transforms();\n\n transforms.setConfig(macros);\n\n let { setOwnConfig, setConfig, configure } = options;\n\n if (setOwnConfig) {\n macros.setOwnConfig(root, setOwnConfig);\n }\n\n if (setConfig) {\n for (let [packageName, config] of Object.entries(setConfig)) {\n macros.setConfig(root, packageName, config as object);\n }\n }\n\n configure?.(macros);\n\n if (process.env.NODE_ENV === 'development') {\n macros.enablePackageDevelopment(process.cwd());\n macros.enableRuntimeMode();\n }\n\n // `buildMacros` is only ever called under Embroider 4.x, where the eager\n // implementation is mandatory.\n macros.importSyncImplementation = 'eager';\n\n macros.finalize();\n\n return {\n babelMacros: macros.babelPluginConfig(),\n templateMacros: transforms.plugins,\n };\n}\n"]}
@@ -0,0 +1,9 @@
1
+ declare const _default: {
2
+ name: string;
3
+ included(this: any, parent: any): void;
4
+ installBabelPlugin(this: any, appOrAddonInstance: any): void;
5
+ setupPreprocessorRegistry(this: any, type: "parent" | "self", registry: any): void;
6
+ options: {};
7
+ };
8
+ export = _default;
9
+ //# sourceMappingURL=ember-addon-main.d.ts.map
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ const path_1 = require("path");
3
+ const node_1 = require("./node");
4
+ let hasWrappedToTree = false;
5
+ // this can differ from appInstance.project.root because Dummy apps are terrible
6
+ function getAppRoot(appInstance) {
7
+ return (0, path_1.join)(appInstance.project.configPath(), '..', '..');
8
+ }
9
+ function getMacrosConfig(appInstance) {
10
+ let appRoot = (0, path_1.join)(appInstance.project.configPath(), '..', '..');
11
+ return node_1.MacrosConfig.for(appInstance, appRoot);
12
+ }
13
+ module.exports = {
14
+ name: '@embroider/macros',
15
+ included(parent) {
16
+ this._super.included.apply(this, arguments);
17
+ this.options.babel = { plugins: [] };
18
+ let parentOptions = (parent.options = parent.options || {});
19
+ let ownOptions = (parentOptions['@embroider/macros'] = parentOptions['@embroider/macros'] || {});
20
+ let appInstance = this._findHost();
21
+ let macrosConfig = getMacrosConfig(appInstance);
22
+ this.setMacrosConfig(macrosConfig);
23
+ // if parent is an addon it has root. If it's an app it has project.root.
24
+ let source = parent.root || parent.project.root;
25
+ if (ownOptions.setOwnConfig) {
26
+ macrosConfig.setOwnConfig(source, ownOptions.setOwnConfig);
27
+ }
28
+ if (ownOptions.setConfig) {
29
+ for (let [packageName, config] of Object.entries(ownOptions.setConfig)) {
30
+ macrosConfig.setConfig(source, packageName, config);
31
+ }
32
+ }
33
+ if (appInstance.env !== 'production') {
34
+ // tell the macros our app is under development
35
+ macrosConfig.enablePackageDevelopment(getAppRoot(appInstance));
36
+ // also tell them our root project is under development. This can be
37
+ // different, in the case where this is an addon and the app is the dummy
38
+ // app.
39
+ macrosConfig.enablePackageDevelopment(appInstance.project.root);
40
+ // keep the macros in runtime mode for development & testing
41
+ macrosConfig.enableRuntimeMode();
42
+ }
43
+ // add our babel plugin to our parent's babel
44
+ this.installBabelPlugin(parent);
45
+ // and to our own babel, because we may need to inline runtime config into
46
+ // our source code
47
+ this.installBabelPlugin(this);
48
+ appInstance.import('vendor/embroider-macros-test-support.js', { type: 'test' });
49
+ const originalToTree = appInstance.toTree;
50
+ if (!hasWrappedToTree) {
51
+ // When we're used inside the traditional ember-cli build pipeline without
52
+ // Embroider, we unfortunately need to hook into here uncleanly because we
53
+ // need to delineate the point in time after which writing macro config is
54
+ // forbidden and consuming it becomes allowed. There's no existing hook with
55
+ // that timing.
56
+ appInstance.toTree = function (...args) {
57
+ macrosConfig.finalize();
58
+ return originalToTree.apply(appInstance, args);
59
+ };
60
+ hasWrappedToTree = true;
61
+ }
62
+ },
63
+ // Other addons are allowed to call this. It's needed if an addon needs to
64
+ // emit code containing macros into that addon's parent (via a babel plugin,
65
+ // for exmple). This is only an issue in classic builds, under embroider all
66
+ // babel plugins should be thought of as *language extensions* that are
67
+ // available everywhere, we don't scope them so narrowly so this probably
68
+ // doesn't come up.
69
+ installBabelPlugin(appOrAddonInstance) {
70
+ let babelOptions = (appOrAddonInstance.options.babel = appOrAddonInstance.options.babel || {});
71
+ let babelPlugins = (babelOptions.plugins = babelOptions.plugins || []);
72
+ if (!babelPlugins.some(node_1.isEmbroiderMacrosPlugin)) {
73
+ let appInstance = this._findHost();
74
+ babelPlugins.unshift(...getMacrosConfig(appInstance).babelPluginConfig(appOrAddonInstance));
75
+ }
76
+ },
77
+ setupPreprocessorRegistry(type, registry) {
78
+ if (type === 'parent') {
79
+ // the htmlbars-ast-plugins are split into two parts because order is
80
+ // important. Weirdly, they appear to run in the reverse order that you
81
+ // register them here.
82
+ //
83
+ // MacrosConfig.astPlugins is static because in classic ember-cli, at this
84
+ // point there's not yet an appInstance, so we defer getting it and
85
+ // calling setConfig until our included hook.
86
+ let { plugins, setConfig, lazyParams } = node_1.MacrosConfig.astPlugins(this.parent.root);
87
+ this.setMacrosConfig = setConfig;
88
+ plugins.forEach((plugin, index) => {
89
+ let name = `@embroider/macros/${index}`;
90
+ let baseDir = (0, path_1.join)(__dirname, '..');
91
+ let params = {
92
+ name,
93
+ firstTransformParams: lazyParams,
94
+ methodName: index === 0 ? 'makeSecondTransform' : 'makeFirstTransform',
95
+ baseDir,
96
+ };
97
+ registry.add('htmlbars-ast-plugin', {
98
+ name,
99
+ plugin,
100
+ parallelBabel: {
101
+ requireFile: (0, path_1.join)(__dirname, 'glimmer', 'ast-transform.js'),
102
+ buildUsing: 'buildPlugin',
103
+ params,
104
+ },
105
+ baseDir: () => baseDir,
106
+ });
107
+ });
108
+ }
109
+ },
110
+ options: {},
111
+ };
112
+ //# sourceMappingURL=ember-addon-main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ember-addon-main.js","sourceRoot":"","sources":["ember-addon-main.ts"],"names":[],"mappings":";AACA,+BAA4B;AAE5B,iCAA+D;AAE/D,IAAI,gBAAgB,GAAG,KAAK,CAAC;AAqH7B,gFAAgF;AAChF,SAAS,UAAU,CAAC,WAAwB;IAC1C,OAAO,IAAA,WAAI,EAAC,WAAW,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAC5D,CAAC;AAED,SAAS,eAAe,CAAC,WAAwB;IAC/C,IAAI,OAAO,GAAG,IAAA,WAAI,EAAC,WAAW,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IACjE,OAAO,mBAAY,CAAC,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AAChD,CAAC;AA3HD,iBAAS;IACP,IAAI,EAAE,mBAAmB;IACzB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import { join } from 'path';\nimport type { BuildPluginParams } from './glimmer/ast-transform';\nimport { MacrosConfig, isEmbroiderMacrosPlugin } from './node';\n\nlet hasWrappedToTree = false;\n\nexport = {\n name: '@embroider/macros',\n included(this: any, parent: any) {\n this._super.included.apply(this, arguments);\n this.options.babel = { plugins: [] };\n let parentOptions = (parent.options = parent.options || {});\n let ownOptions = (parentOptions['@embroider/macros'] = parentOptions['@embroider/macros'] || {});\n\n let appInstance: AppInstance = this._findHost();\n let macrosConfig = getMacrosConfig(appInstance);\n this.setMacrosConfig(macrosConfig);\n\n // if parent is an addon it has root. If it's an app it has project.root.\n let source = parent.root || parent.project.root;\n\n if (ownOptions.setOwnConfig) {\n macrosConfig.setOwnConfig(source, ownOptions.setOwnConfig);\n }\n\n if (ownOptions.setConfig) {\n for (let [packageName, config] of Object.entries(ownOptions.setConfig)) {\n macrosConfig.setConfig(source, packageName, config as object);\n }\n }\n\n if (appInstance.env !== 'production') {\n // tell the macros our app is under development\n macrosConfig.enablePackageDevelopment(getAppRoot(appInstance));\n // also tell them our root project is under development. This can be\n // different, in the case where this is an addon and the app is the dummy\n // app.\n macrosConfig.enablePackageDevelopment(appInstance.project.root);\n // keep the macros in runtime mode for development & testing\n macrosConfig.enableRuntimeMode();\n }\n\n // add our babel plugin to our parent's babel\n this.installBabelPlugin(parent);\n\n // and to our own babel, because we may need to inline runtime config into\n // our source code\n this.installBabelPlugin(this);\n\n appInstance.import('vendor/embroider-macros-test-support.js', { type: 'test' });\n\n const originalToTree = appInstance.toTree;\n\n if (!hasWrappedToTree) {\n // When we're used inside the traditional ember-cli build pipeline without\n // Embroider, we unfortunately need to hook into here uncleanly because we\n // need to delineate the point in time after which writing macro config is\n // forbidden and consuming it becomes allowed. There's no existing hook with\n // that timing.\n appInstance.toTree = function (...args) {\n macrosConfig.finalize();\n return originalToTree.apply(appInstance, args);\n };\n hasWrappedToTree = true;\n }\n },\n\n // Other addons are allowed to call this. It's needed if an addon needs to\n // emit code containing macros into that addon's parent (via a babel plugin,\n // for exmple). This is only an issue in classic builds, under embroider all\n // babel plugins should be thought of as *language extensions* that are\n // available everywhere, we don't scope them so narrowly so this probably\n // doesn't come up.\n installBabelPlugin(this: any, appOrAddonInstance: any) {\n let babelOptions = (appOrAddonInstance.options.babel = appOrAddonInstance.options.babel || {});\n let babelPlugins = (babelOptions.plugins = babelOptions.plugins || []);\n if (!babelPlugins.some(isEmbroiderMacrosPlugin)) {\n let appInstance = this._findHost();\n babelPlugins.unshift(...getMacrosConfig(appInstance).babelPluginConfig(appOrAddonInstance));\n }\n },\n\n setupPreprocessorRegistry(this: any, type: 'parent' | 'self', registry: any) {\n if (type === 'parent') {\n // the htmlbars-ast-plugins are split into two parts because order is\n // important. Weirdly, they appear to run in the reverse order that you\n // register them here.\n //\n // MacrosConfig.astPlugins is static because in classic ember-cli, at this\n // point there's not yet an appInstance, so we defer getting it and\n // calling setConfig until our included hook.\n let { plugins, setConfig, lazyParams } = MacrosConfig.astPlugins((this as any).parent.root);\n this.setMacrosConfig = setConfig;\n plugins.forEach((plugin, index) => {\n let name = `@embroider/macros/${index}`;\n let baseDir = join(__dirname, '..');\n\n let params: BuildPluginParams = {\n name,\n firstTransformParams: lazyParams,\n methodName: index === 0 ? 'makeSecondTransform' : 'makeFirstTransform',\n baseDir,\n };\n\n registry.add('htmlbars-ast-plugin', {\n name,\n plugin,\n parallelBabel: {\n requireFile: join(__dirname, 'glimmer', 'ast-transform.js'),\n buildUsing: 'buildPlugin',\n params,\n },\n baseDir: () => baseDir,\n });\n });\n }\n },\n\n options: {},\n};\n\n// this can differ from appInstance.project.root because Dummy apps are terrible\nfunction getAppRoot(appInstance: AppInstance): string {\n return join(appInstance.project.configPath(), '..', '..');\n}\n\nfunction getMacrosConfig(appInstance: AppInstance): MacrosConfig {\n let appRoot = join(appInstance.project.configPath(), '..', '..');\n return MacrosConfig.for(appInstance, appRoot);\n}\n"]}
@@ -0,0 +1,3 @@
1
+ import type { RewrittenPackageCache } from '@embroider/shared-internals';
2
+ export default function appEmberSatisfies(node: any, packageCache: RewrittenPackageCache): boolean;
3
+ //# sourceMappingURL=app-ember-satisfies.d.ts.map
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = appEmberSatisfies;
4
+ const semver_1 = require("semver");
5
+ const packageName = 'ember-source';
6
+ function appEmberSatisfies(node, packageCache) {
7
+ if (node.params.length !== 1) {
8
+ throw new Error(`macroAppEmberSatisfies requires only one argument, you passed ${node.params.length}`);
9
+ }
10
+ if (!node.params.every((p) => p.type === 'StringLiteral')) {
11
+ throw new Error(`all arguments to macroAppEmberSatisfies must be string literals`);
12
+ }
13
+ let root = packageCache.get(packageCache.appRoot);
14
+ let range = node.params[0].value;
15
+ if (!(root === null || root === void 0 ? void 0 : root.hasDependency(packageName))) {
16
+ return false;
17
+ }
18
+ let pkg;
19
+ try {
20
+ pkg = packageCache.resolve(packageName, root);
21
+ }
22
+ catch (err) {
23
+ // it's not an error if we can't resolve it, we just don't satisfy it.
24
+ }
25
+ if (pkg) {
26
+ return (0, semver_1.satisfies)(pkg.version, range, {
27
+ includePrerelease: true,
28
+ });
29
+ }
30
+ return false;
31
+ }
32
+ //# sourceMappingURL=app-ember-satisfies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-ember-satisfies.js","sourceRoot":"","sources":["app-ember-satisfies.ts"],"names":[],"mappings":";;AAKA,oCA6BC;AAlCD,mCAAmC;AAGnC,MAAM,WAAW,GAAG,cAAc,CAAC;AAEnC,SAAwB,iBAAiB,CAAC,IAAS,EAAE,YAAmC;IACtF,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,iEAAiE,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IACzG,CAAC;IAED,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,eAAe,CAAC,EAAE,CAAC;QAC/D,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAC;IACrF,CAAC;IAED,IAAI,IAAI,GAAG,YAAY,CAAC,GAAG,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IAClD,IAAI,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAEjC,IAAI,CAAC,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,aAAa,CAAC,WAAW,CAAC,CAAA,EAAE,CAAC;QACtC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,GAAG,CAAC;IACR,IAAI,CAAC;QACH,GAAG,GAAG,YAAY,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;IAChD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,sEAAsE;IACxE,CAAC;IAED,IAAI,GAAG,EAAE,CAAC;QACR,OAAO,IAAA,kBAAS,EAAC,GAAG,CAAC,OAAO,EAAE,KAAK,EAAE;YACnC,iBAAiB,EAAE,IAAI;SACxB,CAAC,CAAC;IACL,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { satisfies } from 'semver';\nimport type { RewrittenPackageCache } from '@embroider/shared-internals';\n\nconst packageName = 'ember-source';\n\nexport default function appEmberSatisfies(node: any, packageCache: RewrittenPackageCache) {\n if (node.params.length !== 1) {\n throw new Error(`macroAppEmberSatisfies requires only one argument, you passed ${node.params.length}`);\n }\n\n if (!node.params.every((p: any) => p.type === 'StringLiteral')) {\n throw new Error(`all arguments to macroAppEmberSatisfies must be string literals`);\n }\n\n let root = packageCache.get(packageCache.appRoot);\n let range = node.params[0].value;\n\n if (!root?.hasDependency(packageName)) {\n return false;\n }\n\n let pkg;\n try {\n pkg = packageCache.resolve(packageName, root);\n } catch (err) {\n // it's not an error if we can't resolve it, we just don't satisfy it.\n }\n\n if (pkg) {\n return satisfies(pkg.version, range, {\n includePrerelease: true,\n });\n }\n return false;\n}\n"]}
@@ -0,0 +1,133 @@
1
+ export interface BuildPluginParams {
2
+ name: string;
3
+ baseDir: string;
4
+ methodName: string;
5
+ firstTransformParams: FirstTransformParams;
6
+ }
7
+ export interface FirstTransformParams {
8
+ packageRoot: string | undefined;
9
+ appRoot: string;
10
+ configs: {
11
+ [packageRoot: string]: object;
12
+ };
13
+ }
14
+ export declare function buildPlugin(params: BuildPluginParams): {
15
+ name: string;
16
+ plugin: (env: {
17
+ syntax: {
18
+ builders: any;
19
+ };
20
+ meta: {
21
+ moduleName: string;
22
+ };
23
+ filename: string;
24
+ }) => {
25
+ name: string;
26
+ visitor: {
27
+ SubExpression(node: any, walker: {
28
+ parent: {
29
+ node: any;
30
+ };
31
+ }): any;
32
+ MustacheStatement(node: any): any;
33
+ Template: {
34
+ enter: (node: any) => void;
35
+ exit: (node: any) => void;
36
+ };
37
+ Block: {
38
+ enter: (node: any) => void;
39
+ exit: (node: any) => void;
40
+ };
41
+ Program?: undefined;
42
+ } | {
43
+ SubExpression(node: any, walker: {
44
+ parent: {
45
+ node: any;
46
+ };
47
+ }): any;
48
+ MustacheStatement(node: any): any;
49
+ Program: {
50
+ enter: (node: any) => void;
51
+ exit: (node: any) => void;
52
+ };
53
+ Template?: undefined;
54
+ Block?: undefined;
55
+ };
56
+ };
57
+ baseDir: () => string;
58
+ };
59
+ export declare function makeFirstTransform(opts: FirstTransformParams): (env: {
60
+ syntax: {
61
+ builders: any;
62
+ };
63
+ meta: {
64
+ moduleName: string;
65
+ };
66
+ filename: string;
67
+ }) => {
68
+ name: string;
69
+ visitor: {
70
+ SubExpression(node: any, walker: {
71
+ parent: {
72
+ node: any;
73
+ };
74
+ }): any;
75
+ MustacheStatement(node: any): any;
76
+ Template: {
77
+ enter: (node: any) => void;
78
+ exit: (node: any) => void;
79
+ };
80
+ Block: {
81
+ enter: (node: any) => void;
82
+ exit: (node: any) => void;
83
+ };
84
+ Program?: undefined;
85
+ } | {
86
+ SubExpression(node: any, walker: {
87
+ parent: {
88
+ node: any;
89
+ };
90
+ }): any;
91
+ MustacheStatement(node: any): any;
92
+ Program: {
93
+ enter: (node: any) => void;
94
+ exit: (node: any) => void;
95
+ };
96
+ Template?: undefined;
97
+ Block?: undefined;
98
+ };
99
+ };
100
+ export declare function makeSecondTransform(): (env: {
101
+ syntax: {
102
+ builders: any;
103
+ };
104
+ }) => {
105
+ name: string;
106
+ visitor: {
107
+ BlockStatement(node: any): any;
108
+ SubExpression(node: any): any;
109
+ ElementNode(node: any): void;
110
+ MustacheStatement(node: any): any;
111
+ Template: {
112
+ enter: (node: any) => void;
113
+ exit: (node: any) => void;
114
+ };
115
+ Block: {
116
+ enter: (node: any) => void;
117
+ exit: (node: any) => void;
118
+ };
119
+ Program?: undefined;
120
+ } | {
121
+ BlockStatement(node: any): any;
122
+ SubExpression(node: any): any;
123
+ ElementNode(node: any): void;
124
+ MustacheStatement(node: any): any;
125
+ Program: {
126
+ enter: (node: any) => void;
127
+ exit: (node: any) => void;
128
+ };
129
+ Template?: undefined;
130
+ Block?: undefined;
131
+ };
132
+ };
133
+ //# sourceMappingURL=ast-transform.d.ts.map