@discord/intl-loader-core 0.7.1 → 0.8.0-rc.1

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": "@discord/intl-loader-core",
3
- "version": "0.7.1",
3
+ "version": "0.8.0-rc.1",
4
4
  "license": "MIT",
5
5
  "description": "Core utilities for writing loaders and transformers using @discord/intl",
6
6
  "author": "Jon Egeland",
@@ -22,7 +22,7 @@
22
22
  "chokidar": "^3.6.0",
23
23
  "debug": "^4.3.6",
24
24
  "fast-glob": "^3.3.2",
25
- "@discord/intl-message-database": "0.7.1"
25
+ "@discord/intl-message-database": "0.8.0-rc.1"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/debug": "^4.1.12"
@@ -110,6 +110,25 @@ class MessageDefinitionsTransformer {
110
110
  ];
111
111
  }
112
112
 
113
+ /**
114
+ * Return the lines to export fields from this module, as determined by the `exportMode` on this
115
+ * transformer.
116
+ */
117
+ exportFields() {
118
+ switch (this.options.exportMode ?? 'esm') {
119
+ case 'esm':
120
+ return [`export {${this.loaderName}};`, `export default binds;`];
121
+ case 'commonjs':
122
+ return [`module.exports = { messagesLoader: ${this.loaderName}, default: binds };`];
123
+ case 'transpiledEsModule':
124
+ return [
125
+ `Object.defineProperty(exports, "__esModule", { value: true });`,
126
+ `exports["messageLoader"] = ${this.loaderName};`,
127
+ `exports["default"] = binds;`,
128
+ ];
129
+ }
130
+ }
131
+
113
132
  /**
114
133
  * Returns the reduced, transformed output for this file. Currently not
115
134
  * configurable, but could be told to include default messages or preserve
@@ -124,9 +143,10 @@ class MessageDefinitionsTransformer {
124
143
  `const _keys = ${JSON.stringify(this.options.messageKeys)};`,
125
144
  `const _locales = ${this.getLocaleRequireMap()};`,
126
145
  `const _defaultLocale = ${JSON.stringify(this.options.defaultLocale)};`,
127
- `export const ${this.loaderName} = createLoader(_keys, _locales, _defaultLocale);`,
146
+ `const ${this.loaderName} = createLoader(_keys, _locales, _defaultLocale);`,
128
147
  ...this.debugModeSetup(),
129
- `export default ${this.loaderName}.getBinds();`,
148
+ `const binds = ${this.loaderName}.getBinds();`,
149
+ ...this.exportFields(),
130
150
  ].join('\n');
131
151
  }
132
152
  }
package/src/types.d.ts CHANGED
@@ -40,6 +40,17 @@ export interface MessageDefinitionsTransformerOptions {
40
40
  * code to provide context for debugging in errors and warning messages.
41
41
  */
42
42
  debug?: boolean;
43
+ /**
44
+ * Control how value exports are written in the transformed file to match what any downstream
45
+ * transformer or interpreter may expect. `esm` will leave exports as `export default` and other
46
+ * module features supported in ES6 and onward. `commonjs` will explicitly use `module.exports`
47
+ * with a single object containing `default` as the key for a default export. `transpiledEsModule`
48
+ * does the same, but includes the compatibility field `__esModule` to indicate that the module
49
+ * "was transpiled" to this syntax.
50
+ *
51
+ * @default esm
52
+ */
53
+ exportMode?: 'esm' | 'commonjs' | 'transpiledEsModule';
43
54
  }
44
55
 
45
56
  /**