Skip to content

Commit 94e6234

Browse files
committed
fix(wasm): store with hash also in the standalone environment
1 parent 9f16e5e commit 94e6234

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

src/wasm/plugin.ts

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -92,24 +92,23 @@ export default function webAssemblySupport(
9292
}
9393

9494
const cleanCode = code.replace(WASM_DIRECTIVE_REGEX, "");
95-
const fileName = path.basename(id);
95+
const idUniqueHash = createHash("sha1")
96+
.update(id)
97+
.digest("hex")
98+
.slice(0, 8);
99+
const fileName = `${idUniqueHash}-${path.basename(id, TS_EXTENSION)}`;
96100
const cwd = process.cwd();
97-
const wasmFileName = fileName.replace(TS_EXTENSION, WASM_EXTENSION);
98-
const wasmTextFileName = fileName.replace(
99-
TS_EXTENSION,
100-
WASM_TEXT_EXTENSION
101-
);
102-
const jsBindingsFileName = fileName.replace(TS_EXTENSION, JS_EXTENSION);
103-
const dTsFileName = fileName.replace(TS_EXTENSION, D_TS_EXTENSION);
104-
const sourceMapFileName = fileName.replace(
105-
TS_EXTENSION,
106-
WASM_MAP_EXTENSION
107-
);
101+
const tsFilePath = `${fileName}${TS_EXTENSION}`;
102+
const wasmFileName = `${fileName}${WASM_EXTENSION}`;
103+
const wasmTextFileName = `${fileName}${WASM_TEXT_EXTENSION}`;
104+
const jsBindingsFileName = `${fileName}${JS_EXTENSION}`;
105+
const dTsFileName = `${fileName}${D_TS_EXTENSION}`;
106+
const sourceMapFileName = `${fileName}${WASM_MAP_EXTENSION}`;
108107

109108
const standaloneEnvironment = new StandaloneEnvironment(cwd);
110109
const tempCodeFileName = path.join(
111110
standaloneEnvironment.standaloneOutputPath,
112-
fileName
111+
tsFilePath
113112
);
114113
await standaloneEnvironment.setup();
115114
const outFilePath = path.join(
@@ -182,19 +181,9 @@ export default function webAssemblySupport(
182181
readJson(sourceMapPath, "utf-8"),
183182
]);
184183

185-
const idUniqueHash = createHash("sha1")
186-
.update(id)
187-
.digest("hex")
188-
.slice(0, 8);
189-
const wasmDistPath = path.join(
190-
"wasm",
191-
`${idUniqueHash}-${wasmFileName}`
192-
);
193-
const wasmTextDistPath = path.join(
194-
"wasm",
195-
`${idUniqueHash}-${wasmTextFileName}`
196-
);
197-
const dTsDistPath = path.join("wasm", `${idUniqueHash}-${dTsFileName}`);
184+
const wasmDistPath = path.join("wasm", wasmFileName);
185+
const wasmTextDistPath = path.join("wasm", wasmTextFileName);
186+
const dTsDistPath = path.join("wasm", dTsFileName);
198187

199188
const referenceId = (this as any).emitFile({
200189
type: "asset",
@@ -212,7 +201,11 @@ export default function webAssemblySupport(
212201
source: dTsContent,
213202
});
214203

215-
await standaloneEnvironment.clean();
204+
try {
205+
await standaloneEnvironment.clean();
206+
} catch (error) {
207+
console.warn("Not possible to clean standalone environment:", error);
208+
}
216209

217210
const resolvedBindings = generatedBindings.replace(
218211
BINDINGS_DEFAULT_WASM_URL_REGEX,

0 commit comments

Comments
 (0)