@embroider/macros 1.17.0-alpha.4 → 1.17.0-alpha.5

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/README.md CHANGED
@@ -10,6 +10,45 @@ The [Embroider package spec](../../docs/spec.md) proposes fixing this by making
10
10
 
11
11
  This package works in both Embroider and Classical builds, so that addon authors can switch to this newer pattern without disruption.
12
12
 
13
+ ## Setting Configuration: from a babel config
14
+
15
+ 1. Add `@embroider/macros` as `devDependency`.
16
+ 2. In your babel config, do:
17
+
18
+ ```js
19
+ const { buildMacros } = require('@embroider/macros/babel');
20
+
21
+ const macros = buildMacros({
22
+ // this is how you configure your own package
23
+ setOwnConfig: {
24
+ // your config goes here
25
+ },
26
+ // this is how you can optionally send configuration into your
27
+ // dependencies, if those dependencies choose to use
28
+ // @embroider/macros configs.
29
+ setConfig: {
30
+ 'some-dependency': {
31
+ // config for some-dependency
32
+ },
33
+ },
34
+ });
35
+
36
+ module.exports = {
37
+ plugins: [
38
+ // ...
39
+ [
40
+ "babel-plugin-ember-template-compilation",
41
+ {
42
+ compilerPath: "ember-source/dist/ember-template-compiler.js",
43
+ transforms: [...macros.templateMacros],
44
+ },
45
+ ],
46
+ ...macros.babelMacros,
47
+ ],
48
+ // ...
49
+ };
50
+ ```
51
+
13
52
  ## Setting Configuration: from an Ember app
14
53
 
15
54
  1. Add `@embroider/macros` as `devDependency`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embroider/macros",
3
- "version": "1.17.0-alpha.4",
3
+ "version": "1.17.0-alpha.5",
4
4
  "private": false,
5
5
  "description": "Standardized build-time macros for ember apps.",
6
6
  "keywords": [
@@ -14,6 +14,11 @@
14
14
  "license": "MIT",
15
15
  "author": "Edward Faulkner",
16
16
  "main": "src/index.js",
17
+ "exports": {
18
+ ".": "./src/index.js",
19
+ "./babel": "./src/babel.js",
20
+ "./src/*": "./src/*.js"
21
+ },
17
22
  "files": [
18
23
  "src/**/*.js",
19
24
  "src/**/*.d.ts",
@@ -54,8 +59,8 @@
54
59
  "code-equality-assertions": "^1.0.1",
55
60
  "scenario-tester": "^3.0.1",
56
61
  "typescript": "^5.4.5",
57
- "@embroider/core": "4.0.0-alpha.5",
58
- "@embroider/test-support": "0.36.0"
62
+ "@embroider/test-support": "0.36.0",
63
+ "@embroider/core": "4.0.0-alpha.6"
59
64
  },
60
65
  "peerDependencies": {
61
66
  "@glint/template": "^1.0.0"
package/src/babel.d.ts ADDED
@@ -0,0 +1,46 @@
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 {};
package/src/babel.js ADDED
@@ -0,0 +1,33 @@
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
+ macros.finalize();
28
+ return {
29
+ babelMacros: macros.babelPluginConfig(),
30
+ templateMacros: transforms.plugins,
31
+ };
32
+ }
33
+ //# sourceMappingURL=babel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babel.js","sourceRoot":"","sources":["babel.ts"],"names":[],"mappings":";;;;;AAiDA,kCAiCC;AAlFD,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,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 macros.finalize();\n\n return {\n babelMacros: macros.babelPluginConfig(),\n templateMacros: transforms.plugins,\n };\n}\n"]}