@embroider/macros 1.8.0 → 1.8.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embroider/macros",
3
- "version": "1.8.0",
3
+ "version": "1.8.3",
4
4
  "private": false,
5
5
  "description": "Standardized build-time macros for ember apps.",
6
6
  "keywords": [
@@ -24,7 +24,7 @@
24
24
  "test": "jest"
25
25
  },
26
26
  "dependencies": {
27
- "@embroider/shared-internals": "1.8.0",
27
+ "@embroider/shared-internals": "1.8.3",
28
28
  "assert-never": "^1.2.1",
29
29
  "babel-import-util": "^1.1.0",
30
30
  "ember-cli-babel": "^7.26.6",
@@ -36,7 +36,7 @@
36
36
  "devDependencies": {
37
37
  "@babel/core": "^7.14.5",
38
38
  "@babel/traverse": "^7.14.5",
39
- "@embroider/core": "1.8.0",
39
+ "@embroider/core": "1.8.3",
40
40
  "@embroider/test-support": "0.36.0",
41
41
  "@types/babel__core": "^7.1.14",
42
42
  "@types/babel__generator": "^7.6.2",
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  const path_1 = require("path");
3
3
  const node_1 = require("./node");
4
+ let hasWrappedToTree = false;
4
5
  // this can differ from appInstance.project.root because Dummy apps are terrible
5
6
  function getAppRoot(appInstance) {
6
7
  return (0, path_1.join)(appInstance.project.configPath(), '..', '..');
@@ -45,16 +46,19 @@ module.exports = {
45
46
  // our source code
46
47
  this.installBabelPlugin(this);
47
48
  appInstance.import('vendor/embroider-macros-test-support.js', { type: 'test' });
48
- // When we're used inside the traditional ember-cli build pipeline without
49
- // Embroider, we unfortunately need to hook into here uncleanly because we
50
- // need to delineate the point in time after which writing macro config is
51
- // forbidden and consuming it becomes allowed. There's no existing hook with
52
- // that timing.
53
49
  const originalToTree = appInstance.toTree;
54
- appInstance.toTree = function (...args) {
55
- macrosConfig.finalize();
56
- return originalToTree.apply(appInstance, args);
57
- };
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
+ }
58
62
  },
59
63
  // Other addons are allowed to call this. It's needed if an addon needs to
60
64
  // emit code containing macros into that addon's parent (via a babel plugin,
@@ -1 +1 @@
1
- {"version":3,"file":"ember-addon-main.js","sourceRoot":"","sources":["ember-addon-main.ts"],"names":[],"mappings":";AACA,+BAA4B;AAE5B,iCAA+D;AAiH/D,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;AAvHD,iBAAS;IACP,IAAI,EAAE,mBAAmB;IACzB,QAAQ,CAAY,MAAW;QAC7B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QAC5C,IAAI,CAAC,OAAO,CAAC,KAAK,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;QACrC,IAAI,aAAa,GAAG,CAAC,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;QAC5D,IAAI,UAAU,GAAG,CAAC,aAAa,CAAC,mBAAmB,CAAC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,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;gBAChC,IAAI,IAAI,GAAG,qBAAqB,KAAK,EAAE,CAAC;gBACxC,IAAI,OAAO,GAAG,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,CAAC,CAAC;gBAEpC,IAAI,MAAM,GAAsB;oBAC9B,IAAI;oBACJ,oBAAoB,EAAE,UAAU;oBAChC,UAAU,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,oBAAoB;oBACtE,OAAO;iBACR,CAAC;gBAEF,QAAQ,CAAC,GAAG,CAAC,qBAAqB,EAAE;oBAClC,IAAI;oBACJ,MAAM;oBACN,aAAa,EAAE;wBACb,WAAW,EAAE,IAAA,WAAI,EAAC,SAAS,EAAE,SAAS,EAAE,kBAAkB,CAAC;wBAC3D,UAAU,EAAE,aAAa;wBACzB,MAAM;qBACP;oBACD,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO;iBACvB,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;IAED,OAAO,EAAE,EAAE;CACZ,CAAC","sourcesContent":["import { AppInstance } from '@embroider/shared-internals';\nimport { join } from 'path';\nimport { BuildPluginParams } from './glimmer/ast-transform';\nimport { MacrosConfig, isEmbroiderMacrosPlugin } from './node';\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 // 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 const originalToTree = appInstance.toTree;\n appInstance.toTree = function (...args) {\n macrosConfig.finalize();\n return originalToTree.apply(appInstance, args);\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"]}
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,QAAQ,CAAY,MAAW;QAC7B,IAAI,C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CAAC;IAED,yBAAyB,CAAY,IAAuB,EAAE,QAAa;QACzE,IAAI,IAAI,KAAK,QAAQ,EAAE;YACrB,qEAAqE;YACrE,uEAAuE;YACvE,sBAAsB;YACtB,EAAE;YACF,0EAA0E;YAC1E,mEAAmE;YACnE,6CAA6C;YAC7C,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,mBAAY,CAAC,UAAU,CAAE,IAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAC5F,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;YACjC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;gBAChC,IAAI,IAAI,GAAG,qBAAqB,KAAK,EAAE,CAAC;gBACxC,IAAI,OAAO,GAAG,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,CAAC,CAAC;gBAEpC,IAAI,MAAM,GAAsB;oBAC9B,IAAI;oBACJ,oBAAoB,EAAE,UAAU;oBAChC,UAAU,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,oBAAoB;oBACtE,OAAO;iBACR,CAAC;gBAEF,QAAQ,CAAC,GAAG,CAAC,qBAAqB,EAAE;oBAClC,IAAI;oBACJ,MAAM;oBACN,aAAa,EAAE;wBACb,WAAW,EAAE,IAAA,WAAI,EAAC,SAAS,EAAE,SAAS,EAAE,kBAAkB,CAAC;wBAC3D,UAAU,EAAE,aAAa;wBACzB,MAAM;qBACP;oBACD,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO;iBACvB,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;IAED,OAAO,EAAE,EAAE;CACZ,CAAC","sourcesContent":["import { AppInstance } from '@embroider/shared-internals';\nimport { join } from 'path';\nimport { 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"]}