Skip to content

Commit 4c05d63

Browse files
Templatize the package.json
1 parent cda3569 commit 4c05d63

File tree

2 files changed

+15
-24
lines changed

2 files changed

+15
-24
lines changed

Plugins/PackageToJS/Sources/PackageToJS.swift

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -196,31 +196,9 @@ struct PackagingPlanner {
196196
}
197197
packageInputs.append(wasm)
198198

199-
// Write package.json
200-
let packageJSON = make.addTask(
201-
inputFiles: [selfPath], inputTasks: [outputDirTask],
202-
output: outputDir.appending(path: "package.json").path
203-
) {
204-
let packageJSON = """
205-
{
206-
"name": "\(options.packageName ?? packageId.lowercased())",
207-
"version": "0.0.0",
208-
"type": "module",
209-
"exports": {
210-
".": "./index.js",
211-
"./wasm": "./\(wasmFilename)"
212-
},
213-
"dependencies": {
214-
"@bjorn3/browser_wasi_shim": "^0.4.1"
215-
}
216-
}
217-
"""
218-
try packageJSON.write(toFile: $0.output, atomically: true, encoding: .utf8)
219-
}
220-
packageInputs.append(packageJSON)
221-
222199
// Copy the template files
223200
for (file, output) in [
201+
("Plugins/PackageToJS/Templates/package.json", "package.json"),
224202
("Plugins/PackageToJS/Templates/index.js", "index.js"),
225203
("Plugins/PackageToJS/Templates/index.d.ts", "index.d.ts"),
226204
("Plugins/PackageToJS/Templates/instantiate.js", "instantiate.js"),
@@ -278,7 +256,8 @@ struct PackagingPlanner {
278256
) -> MiniMake.TaskKey {
279257
let inputPath = selfPackageDir.appending(path: file)
280258
let substitutions = [
281-
"@PACKAGE_TO_JS_MODULE_PATH@": wasmFilename
259+
"PACKAGE_TO_JS_MODULE_PATH": wasmFilename,
260+
"PACKAGE_TO_JS_PACKAGE_NAME": options.packageName ?? packageId.lowercased(),
282261
]
283262
let (buildConfiguration, triple) = deriveBuildConfiguration()
284263
let conditions = [
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "@PACKAGE_TO_JS_PACKAGE_NAME@",
3+
"version": "0.0.0",
4+
"type": "module",
5+
"exports": {
6+
".": "./index.js",
7+
"./wasm": "./@PACKAGE_TO_JS_MODULE_PATH@"
8+
},
9+
"dependencies": {
10+
"@bjorn3/browser_wasi_shim": "^0.4.1"
11+
}
12+
}

0 commit comments

Comments
 (0)