@discord/metro-intl-transformer 0.11.6 → 0.13.0
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/asset-plugin.js +33 -10
- package/package.json +3 -3
package/asset-plugin.js
CHANGED
|
@@ -66,31 +66,51 @@ const defaultConfig = {
|
|
|
66
66
|
* the desired configuration for that run of the bundler. If the Metro configuration for the current
|
|
67
67
|
* process is at a non-default location, this method will likely fail.
|
|
68
68
|
*
|
|
69
|
-
* @returns {Promise<ResolvedIntlAssetPluginConfig>}
|
|
69
|
+
* @returns {Promise<[ResolvedIntlAssetPluginConfig, import('metro-config').ConfigT]>}
|
|
70
70
|
*/
|
|
71
71
|
async function fetchConfig() {
|
|
72
72
|
debug(`Loading Metro config`);
|
|
73
73
|
const metroConfig = await metro.loadConfig();
|
|
74
|
+
const watchFolders = [metroConfig.projectRoot, ...metroConfig.watchFolders];
|
|
74
75
|
const defaults = {
|
|
75
76
|
...defaultConfig,
|
|
76
|
-
watchFolders
|
|
77
|
+
watchFolders,
|
|
77
78
|
};
|
|
78
79
|
|
|
79
|
-
|
|
80
|
-
const config =
|
|
80
|
+
/** @type {IntlAssetPluginConfig} */
|
|
81
|
+
const config =
|
|
82
|
+
// @ts-expect-error We're latching on `intlAssetPlugin` as a field in the transformer config.
|
|
83
|
+
metroConfig.transformer?.intlAssetPlugin;
|
|
81
84
|
if (config == null) {
|
|
82
85
|
debug('asset-plugin configuration was empty. Using defaults: %O', defaults);
|
|
83
|
-
return { ...defaults };
|
|
86
|
+
return [{ ...defaults }, metroConfig];
|
|
84
87
|
}
|
|
85
88
|
debug(`discovered asset-plugin configuration: %O`, config);
|
|
89
|
+
const resolved = {
|
|
90
|
+
...defaults,
|
|
91
|
+
...config,
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
if (resolved.cacheDir == null) {
|
|
95
|
+
throw new Error(
|
|
96
|
+
'metro-intl-transformer asset-plugin cacheDir configuration resolved to null. Assets cannot be compiled',
|
|
97
|
+
);
|
|
98
|
+
}
|
|
86
99
|
|
|
87
|
-
|
|
100
|
+
const cacheDir = path.resolve(metroConfig.projectRoot, resolved.cacheDir);
|
|
101
|
+
const cacheDirIsWatched = watchFolders.some((folder) => {
|
|
102
|
+
const relative = path.relative(folder, resolved.cacheDir);
|
|
103
|
+
return !relative.startsWith('..');
|
|
104
|
+
});
|
|
105
|
+
if (!cacheDirIsWatched) {
|
|
88
106
|
throw new Error(
|
|
89
|
-
|
|
107
|
+
"metro-intl-transformer cacheDir is not visible to metro's file watching. Assets cannot be used after compilation",
|
|
90
108
|
);
|
|
91
109
|
}
|
|
92
110
|
|
|
93
|
-
|
|
111
|
+
resolved.cacheDir = cacheDir;
|
|
112
|
+
debug(`Resolved cache directory to ${resolved.cacheDir}`);
|
|
113
|
+
return [{ ...defaults, ...config }, metroConfig];
|
|
94
114
|
}
|
|
95
115
|
|
|
96
116
|
const pluginConfig = fetchConfig();
|
|
@@ -101,7 +121,8 @@ let hasInitializedAllDefinitions = false;
|
|
|
101
121
|
* @param {any} assetData
|
|
102
122
|
*/
|
|
103
123
|
async function transformAsset(assetData) {
|
|
104
|
-
const
|
|
124
|
+
const [config, metroConfig] = await pluginConfig;
|
|
125
|
+
const { cacheDir, assetExtension, format, bundleSecrets, watchFolders } = config;
|
|
105
126
|
|
|
106
127
|
if (!hasInitializedAllDefinitions) {
|
|
107
128
|
debug('Initializing database with all messages files within watch folders: %O', watchFolders);
|
|
@@ -123,7 +144,9 @@ async function transformAsset(assetData) {
|
|
|
123
144
|
|
|
124
145
|
debug(`[${filename}] Processing translation asset`);
|
|
125
146
|
|
|
126
|
-
const
|
|
147
|
+
const relativeLocation = path.relative(metroConfig.projectRoot, assetData.fileSystemLocation);
|
|
148
|
+
const dirHash = btoa(path.dirname(relativeLocation));
|
|
149
|
+
const outputDir = path.resolve(cacheDir, dirHash);
|
|
127
150
|
const outputName = `${assetData.name}.${assetData.hash}.compiled.messages`;
|
|
128
151
|
const outputFile = path.join(outputDir, outputName) + '.' + assetExtension;
|
|
129
152
|
debug(`[${filename}] Output file path: ${outputFile}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@discord/metro-intl-transformer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
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.
|
|
18
|
-
"@discord/intl-loader-core": "0.
|
|
17
|
+
"@discord/babel-plugin-transform-discord-intl": "0.13.0",
|
|
18
|
+
"@discord/intl-loader-core": "0.13.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@types/debug": "^4.1.12"
|