@discord/metro-intl-transformer 0.16.0 → 0.16.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.
Files changed (2) hide show
  1. package/asset-plugin.js +22 -3
  2. package/package.json +3 -3
package/asset-plugin.js CHANGED
@@ -42,6 +42,14 @@ const {
42
42
  *
43
43
  * This configuration also automatically reads `projectRoot` and replaces `process.cwd()` when it
44
44
  * has been specified.
45
+ *
46
+ * @property {string} publicPath
47
+ * The path where assets are served from on Metro's HTTP server, used during development. Defaults
48
+ * to `/assets`, which is the default path Metro assigns internally. Any overwritten path should
49
+ * also include `/assets` as the base path for Metro to understand how to serve it.
50
+ *
51
+ * When rewriting an asset after compilation, this path will be prepended to the cache directory
52
+ * where messages were compiled to, creating a full path for Metro to access the asset at runtime.
45
53
  */
46
54
 
47
55
  /**
@@ -55,6 +63,7 @@ const defaultConfig = {
55
63
  format: IntlCompiledMessageFormat.KeylessJson,
56
64
  bundleSecrets: false,
57
65
  watchFolders: [process.cwd()],
66
+ publicPath: '/assets',
58
67
  };
59
68
 
60
69
  /**
@@ -75,6 +84,7 @@ async function fetchConfig() {
75
84
  const defaults = {
76
85
  ...defaultConfig,
77
86
  watchFolders,
87
+ publicPath: metroConfig.transformer?.publicPath ?? defaultConfig.publicPath,
78
88
  };
79
89
 
80
90
  /** @type {IntlAssetPluginConfig} */
@@ -146,7 +156,8 @@ async function transformAsset(assetData) {
146
156
 
147
157
  const relativeLocation = path.relative(metroConfig.projectRoot, assetData.fileSystemLocation);
148
158
  const dirHash = btoa(path.dirname(relativeLocation));
149
- const outputDir = path.resolve(cacheDir, dirHash);
159
+ const relativeOutputDir = path.join(cacheDir, dirHash);
160
+ const outputDir = path.resolve(relativeOutputDir);
150
161
  const outputName = `${assetData.name}.${assetData.hash}.compiled.messages`;
151
162
  const outputFile = path.join(outputDir, outputName) + '.' + assetExtension;
152
163
  debug(`[${filename}] Output file path: ${outputFile}`);
@@ -156,20 +167,28 @@ async function transformAsset(assetData) {
156
167
  fs.mkdirSync(outputDir, { recursive: true });
157
168
  }
158
169
 
170
+ debug(`[${filename}] processing file`);
171
+ debug(`[${filename}] ${metroConfig.transformer?.publicPath}`);
172
+
159
173
  const result = processTranslationsFile(filename);
174
+ debug(`[${filename}] precompiling file`);
160
175
  precompileFileForLocale(filename, result.locale, outputFile, {
161
176
  format,
162
177
  bundleSecrets,
163
178
  });
179
+ debug(`[${filename}] finished precompiling`);
164
180
 
165
- return {
181
+ const finalAssetData = {
166
182
  ...assetData,
167
183
  fileSystemLocation: outputDir,
168
- httpServerLocation: `${assetData.httpServerLocation}/${cacheDir}`,
184
+ httpServerLocation: path.join(config.publicPath, relativeOutputDir),
169
185
  files: [outputFile],
170
186
  name: outputName,
171
187
  type: assetExtension,
172
188
  };
189
+
190
+ debug(`[${filename}] Asset data: %O`, finalAssetData);
191
+ return finalAssetData;
173
192
  }
174
193
 
175
194
  module.exports = transformAsset;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@discord/metro-intl-transformer",
3
- "version": "0.16.0",
3
+ "version": "0.16.1",
4
4
  "license": "MIT",
5
5
  "description": "Metro/Babel transformer plugin for compiling, bundling, and minifying intl message definitions and usages using intl-message-database.",
6
6
  "exports": {
@@ -14,8 +14,8 @@
14
14
  "dependencies": {
15
15
  "debug": "^4.3.6",
16
16
  "metro-config": "^0.81.0",
17
- "@discord/babel-plugin-transform-discord-intl": "0.16.0",
18
- "@discord/intl-loader-core": "0.16.0"
17
+ "@discord/babel-plugin-transform-discord-intl": "0.16.1",
18
+ "@discord/intl-loader-core": "0.16.1"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@types/debug": "^4.1.12"