zile 0.0.7 → 0.0.8
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/README.md +38 -3
- package/dist/Cli.d.ts.map +1 -1
- package/dist/Cli.js +2 -0
- package/dist/Cli.js.map +1 -1
- package/dist/internal/cli/commands.d.ts +11 -0
- package/dist/internal/cli/commands.d.ts.map +1 -1
- package/dist/internal/cli/commands.js +40 -0
- package/dist/internal/cli/commands.js.map +1 -1
- package/dist/internal/package.json +21 -20
- package/package.json +1 -21
- package/src/Cli.ts +2 -0
- package/src/Package.test.ts +11 -11
- package/src/Package.ts +2 -2
- package/src/internal/cli/commands.ts +61 -0
package/README.md
CHANGED
|
@@ -305,6 +305,37 @@ Zile also sets these fields if not already present:
|
|
|
305
305
|
- **`type`**: Set to `"module"` (ESM-only)
|
|
306
306
|
- **`sideEffects`**: Set to `false`
|
|
307
307
|
|
|
308
|
+
### `[!start-pkg]`
|
|
309
|
+
|
|
310
|
+
The `[!start-pkg]` comment marker allows you to control which fields from your `package.json` are included when publishing.
|
|
311
|
+
|
|
312
|
+
When using `zile publish:prepare`, only fields that appear **after** the `[!start-pkg]` comment will be picked for the published package. This is useful for excluding development-only fields (like `devDependencies`, `scripts`, or workspace configurations) from the published package.
|
|
313
|
+
|
|
314
|
+
#### Example
|
|
315
|
+
|
|
316
|
+
```diff
|
|
317
|
+
{
|
|
318
|
+
"scripts": {
|
|
319
|
+
"build": "zile build",
|
|
320
|
+
"publish": "zile publish:prepare && npm publish && zile publish:post",
|
|
321
|
+
"test": "vitest"
|
|
322
|
+
},
|
|
323
|
+
"devDependencies": {
|
|
324
|
+
"typescript": "^5.0.0"
|
|
325
|
+
},
|
|
326
|
+
+ "[!start-pkg]": "",
|
|
327
|
+
"name": "my-pkg",
|
|
328
|
+
"version": "0.0.0",
|
|
329
|
+
"type": "module",
|
|
330
|
+
"main": "./src/index.ts",
|
|
331
|
+
"dependencies": {
|
|
332
|
+
"some-lib": "^1.0.0"
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
In this example, when running `zile publish:prepare`, only the fields after `[!start-pkg]` (type, main, and dependencies) will be included in the published package. The scripts and devDependencies will be excluded.
|
|
338
|
+
|
|
308
339
|
## `tsconfig.json` Reference
|
|
309
340
|
|
|
310
341
|
Since `tsc` is used under the hood, Zile also uses fields in your `tsconfig.json` file to determine the output directory and particular settings for transpilation.
|
|
@@ -334,14 +365,18 @@ Usage:
|
|
|
334
365
|
$ zile [root]
|
|
335
366
|
|
|
336
367
|
Commands:
|
|
337
|
-
[root]
|
|
338
|
-
build
|
|
339
|
-
dev
|
|
368
|
+
[root]
|
|
369
|
+
build Build package
|
|
370
|
+
dev Resolve package exports to source for development
|
|
371
|
+
publish:prepare Prepare package for publishing
|
|
372
|
+
publish:post Post-process package after publishing
|
|
340
373
|
|
|
341
374
|
For more info, run any command with the `--help` flag:
|
|
342
375
|
$ zile --help
|
|
343
376
|
$ zile build --help
|
|
344
377
|
$ zile dev --help
|
|
378
|
+
$ zile publish:prepare --help
|
|
379
|
+
$ zile publish:post --help
|
|
345
380
|
|
|
346
381
|
Options:
|
|
347
382
|
--cwd <directory> Working directory to build
|
package/dist/Cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Cli.d.ts","sourceRoot":"","sources":["../src/Cli.ts"],"names":[],"mappings":";AAKA;;;;;GAKG;AACH,wBAAsB,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"Cli.d.ts","sourceRoot":"","sources":["../src/Cli.ts"],"names":[],"mappings":";AAKA;;;;;GAKG;AACH,wBAAsB,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAgB7D;AAED,MAAM,CAAC,OAAO,WAAW,GAAG,CAAC;IAC3B,KAAK,OAAO,GAAG;QACb,sCAAsC;QACtC,IAAI,EAAE,MAAM,EAAE,CAAA;KACf,CAAA;CACF"}
|
package/dist/Cli.js
CHANGED
|
@@ -17,6 +17,8 @@ export async function run(options) {
|
|
|
17
17
|
commands.build(cli.command('dev', 'Resolve package exports to source for development'), {
|
|
18
18
|
link: true,
|
|
19
19
|
});
|
|
20
|
+
commands.preparePublish(cli.command('publish:prepare', 'Prepare package for publishing'));
|
|
21
|
+
commands.postPublish(cli.command('publish:post', 'Post-process package after publishing'));
|
|
20
22
|
cli.help();
|
|
21
23
|
cli.parse(args);
|
|
22
24
|
}
|
package/dist/Cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Cli.js","sourceRoot":"","sources":["../src/Cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AACzB,OAAO,KAAK,QAAQ,MAAM,4BAA4B,CAAA;AACtD,OAAO,OAAO,MAAM,yBAAyB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAA;AAEnE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,GAAG,CAAC,OAAoB;IAC5C,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAA;IAExB,MAAM,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IAC7B,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAE5B,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAA;IACzC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC,CAAA;IACrD,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,mDAAmD,CAAC,EAAE;QACtF,IAAI,EAAE,IAAI;KACX,CAAC,CAAA;
|
|
1
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IACpB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,CAAC,CAAC,CAAA"}
|
|
@@ -14,4 +14,15 @@ export declare namespace build {
|
|
|
14
14
|
tsgo?: boolean | undefined;
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
+
export declare function preparePublish(command: Command): Promise<Command>;
|
|
18
|
+
export declare namespace preparePublish {
|
|
19
|
+
type CommandOptions = build.CommandOptions;
|
|
20
|
+
}
|
|
21
|
+
export declare function postPublish(command: Command): Promise<Command>;
|
|
22
|
+
export declare namespace postPublish {
|
|
23
|
+
type CommandOptions = {
|
|
24
|
+
/** Working directory to publish from */
|
|
25
|
+
cwd?: string | undefined;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
17
28
|
//# sourceMappingURL=commands.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../../src/internal/cli/commands.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../../src/internal/cli/commands.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAGlC,wBAAsB,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,GAAE,KAAK,CAAC,OAAY,oBAiBxE;AAED,MAAM,CAAC,OAAO,WAAW,KAAK,CAAC;IAC7B,KAAK,OAAO,GAAG;QACb,mEAAmE;QACnE,IAAI,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;KAC3B,CAAA;IAED,KAAK,cAAc,GAAG;QACpB,iCAAiC;QACjC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;QACxB,gGAAgG;QAChG,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;QAC5B,iCAAiC;QACjC,IAAI,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;KAC3B,CAAA;CACF;AAED,wBAAsB,cAAc,CAAC,OAAO,EAAE,OAAO,oBAkCpD;AAED,MAAM,CAAC,OAAO,WAAW,cAAc,CAAC;IACtC,KAAK,cAAc,GAAG,KAAK,CAAC,cAAc,CAAA;CAC3C;AAED,wBAAsB,WAAW,CAAC,OAAO,EAAE,OAAO,oBAUjD;AAED,MAAM,CAAC,OAAO,WAAW,WAAW,CAAC;IACnC,KAAK,cAAc,GAAG;QACpB,wCAAwC;QACxC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KACzB,CAAA;CACF"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
1
3
|
import * as Package from '../../Package.js';
|
|
2
4
|
export async function build(command, options = {}) {
|
|
3
5
|
const { link = false } = options;
|
|
@@ -13,4 +15,42 @@ export async function build(command, options = {}) {
|
|
|
13
15
|
console.log(`✔︎ ${link ? 'Linking' : 'Building'} completed successfully`);
|
|
14
16
|
});
|
|
15
17
|
}
|
|
18
|
+
export async function preparePublish(command) {
|
|
19
|
+
return command
|
|
20
|
+
.option('--cwd <directory>', 'Working directory to publish from')
|
|
21
|
+
.action(async (options) => {
|
|
22
|
+
const { cwd = process.cwd() } = options;
|
|
23
|
+
console.log(`→ Preparing package at ${cwd}`);
|
|
24
|
+
// Build the package
|
|
25
|
+
await Package.build({ cwd });
|
|
26
|
+
// Get the package.json path
|
|
27
|
+
const packageJsonPath = path.join(cwd, './package.json');
|
|
28
|
+
// Copy package.json to a temporary file
|
|
29
|
+
fs.copyFileSync(packageJsonPath, packageJsonPath.replace('.json', '.tmp.json'));
|
|
30
|
+
// Read package.json as text to find the marker position
|
|
31
|
+
const content = fs.readFileSync(packageJsonPath, 'utf-8');
|
|
32
|
+
const data = JSON.parse(content);
|
|
33
|
+
// Find all keys that appear before "[!start-pkg]" in the file
|
|
34
|
+
const keys = Object.keys(data);
|
|
35
|
+
const markerIndex = keys.indexOf('[!start-pkg]');
|
|
36
|
+
// Remove all keys up to and including the marker
|
|
37
|
+
const keysToRemove = keys.slice(0, markerIndex + 1);
|
|
38
|
+
for (const key of keysToRemove)
|
|
39
|
+
delete data[key];
|
|
40
|
+
// Write back to package.json
|
|
41
|
+
fs.writeFileSync(packageJsonPath, `${JSON.stringify(data, null, 2)}\n`, 'utf-8');
|
|
42
|
+
console.log(`✔︎ Package at ${cwd} prepared successfully`);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
export async function postPublish(command) {
|
|
46
|
+
return command
|
|
47
|
+
.option('--cwd <directory>', 'Working directory to publish from')
|
|
48
|
+
.action(async (options) => {
|
|
49
|
+
const { cwd = process.cwd() } = options;
|
|
50
|
+
const packageJsonPath = path.join(cwd, './package.json');
|
|
51
|
+
const tmpPackageJsonPath = path.join(cwd, './package.tmp.json');
|
|
52
|
+
if (fs.existsSync(tmpPackageJsonPath))
|
|
53
|
+
fs.renameSync(tmpPackageJsonPath, packageJsonPath);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
16
56
|
//# sourceMappingURL=commands.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commands.js","sourceRoot":"","sources":["../../../src/internal/cli/commands.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"commands.js","sourceRoot":"","sources":["../../../src/internal/cli/commands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAA;AAE3C,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,OAAgB,EAAE,UAAyB,EAAE;IACvE,MAAM,EAAE,IAAI,GAAG,KAAK,EAAE,GAAG,OAAO,CAAA;IAChC,OAAO,OAAO;SACX,MAAM,CAAC,mBAAmB,EAAE,4BAA4B,CAAC;SACzD,MAAM,CAAC,0BAA0B,EAAE,0BAA0B,CAAC;SAC9D,MAAM,CAAC,kBAAkB,EAAE,gE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,EAAE,CAAC,UAAU,CAAC,kBAAkB,CAAC;YAAE,EAAE,CAAC,UAAU,CAAC,kBAAkB,EAAE,eAAe,CAAC,CAAA;IAC3F,CAAC,CAAC,CAAA;AACN,CAAC"}
|
|
@@ -1,19 +1,32 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "zile",
|
|
3
|
-
"type": "module",
|
|
4
|
-
"version": "0.0.7",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"bin": {
|
|
7
|
-
"zile": "./dist/Cli.js"
|
|
8
|
-
},
|
|
9
2
|
"scripts": {
|
|
10
3
|
"build": "bun src/Cli.ts",
|
|
11
|
-
"changeset:publish": "bun
|
|
4
|
+
"changeset:publish": "bun src/Cli.ts publish:prepare && changeset publish && bun src/Cli.ts publish:post",
|
|
12
5
|
"changeset:version": "changeset version",
|
|
13
6
|
"check": "biome check --fix --unsafe",
|
|
14
7
|
"check:types": "tsc -b",
|
|
15
8
|
"test": "vitest --watch=false"
|
|
16
9
|
},
|
|
10
|
+
"packageManager": "bun@1.3.2",
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"@arethetypeswrong/cli": "0.18.2",
|
|
13
|
+
"@biomejs/biome": "^2.2.5",
|
|
14
|
+
"@changesets/changelog-github": "^0.5.0",
|
|
15
|
+
"@changesets/cli": "^2.27.7",
|
|
16
|
+
"@types/node": "^24.7.1",
|
|
17
|
+
"publint": "0.3.14",
|
|
18
|
+
"typescript": "^5.9.3",
|
|
19
|
+
"type-fest": "^5.0.1",
|
|
20
|
+
"vitest": "^3.2.4"
|
|
21
|
+
},
|
|
22
|
+
"[!start-pkg]": "",
|
|
23
|
+
"name": "zile",
|
|
24
|
+
"type": "module",
|
|
25
|
+
"version": "0.0.8",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"bin": {
|
|
28
|
+
"zile": "./dist/Cli.js"
|
|
29
|
+
},
|
|
17
30
|
"files": [
|
|
18
31
|
"dist",
|
|
19
32
|
"src"
|
|
@@ -29,7 +42,6 @@
|
|
|
29
42
|
"default": "./dist/index.js"
|
|
30
43
|
}
|
|
31
44
|
},
|
|
32
|
-
"packageManager": "bun@1.3",
|
|
33
45
|
"dependencies": {
|
|
34
46
|
"cac": "6.7.14",
|
|
35
47
|
"tsconfck": "3.1.6"
|
|
@@ -46,16 +58,5 @@
|
|
|
46
58
|
"optional": true
|
|
47
59
|
}
|
|
48
60
|
},
|
|
49
|
-
"devDependencies": {
|
|
50
|
-
"@arethetypeswrong/cli": "0.18.2",
|
|
51
|
-
"@biomejs/biome": "^2.2.5",
|
|
52
|
-
"@changesets/changelog-github": "^0.5.0",
|
|
53
|
-
"@changesets/cli": "^2.27.7",
|
|
54
|
-
"@types/node": "^24.7.1",
|
|
55
|
-
"publint": "0.3.14",
|
|
56
|
-
"typescript": "^5.9.3",
|
|
57
|
-
"type-fest": "^5.0.1",
|
|
58
|
-
"vitest": "^3.2.4"
|
|
59
|
-
},
|
|
60
61
|
"repository": "wevm/zile"
|
|
61
62
|
}
|
package/package.json
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zile",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.8",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
7
7
|
"zile": "./dist/Cli.js"
|
|
8
8
|
},
|
|
9
|
-
"scripts": {
|
|
10
|
-
"build": "bun src/Cli.ts",
|
|
11
|
-
"changeset:publish": "bun run build && changeset publish",
|
|
12
|
-
"changeset:version": "changeset version",
|
|
13
|
-
"check": "biome check --fix --unsafe",
|
|
14
|
-
"check:types": "tsc -b",
|
|
15
|
-
"test": "vitest --watch=false"
|
|
16
|
-
},
|
|
17
9
|
"files": [
|
|
18
10
|
"dist",
|
|
19
11
|
"src"
|
|
@@ -29,7 +21,6 @@
|
|
|
29
21
|
"default": "./dist/index.js"
|
|
30
22
|
}
|
|
31
23
|
},
|
|
32
|
-
"packageManager": "bun@1.3",
|
|
33
24
|
"dependencies": {
|
|
34
25
|
"cac": "6.7.14",
|
|
35
26
|
"tsconfck": "3.1.6"
|
|
@@ -46,16 +37,5 @@
|
|
|
46
37
|
"optional": true
|
|
47
38
|
}
|
|
48
39
|
},
|
|
49
|
-
"devDependencies": {
|
|
50
|
-
"@arethetypeswrong/cli": "0.18.2",
|
|
51
|
-
"@biomejs/biome": "^2.2.5",
|
|
52
|
-
"@changesets/changelog-github": "^0.5.0",
|
|
53
|
-
"@changesets/cli": "^2.27.7",
|
|
54
|
-
"@types/node": "^24.7.1",
|
|
55
|
-
"publint": "0.3.14",
|
|
56
|
-
"typescript": "^5.9.3",
|
|
57
|
-
"type-fest": "^5.0.1",
|
|
58
|
-
"vitest": "^3.2.4"
|
|
59
|
-
},
|
|
60
40
|
"repository": "wevm/zile"
|
|
61
41
|
}
|
package/src/Cli.ts
CHANGED
|
@@ -20,6 +20,8 @@ export async function run(options: run.Options): Promise<void> {
|
|
|
20
20
|
commands.build(cli.command('dev', 'Resolve package exports to source for development'), {
|
|
21
21
|
link: true,
|
|
22
22
|
})
|
|
23
|
+
commands.preparePublish(cli.command('publish:prepare', 'Prepare package for publishing'))
|
|
24
|
+
commands.postPublish(cli.command('publish:post', 'Post-process package after publishing'))
|
|
23
25
|
|
|
24
26
|
cli.help()
|
|
25
27
|
cli.parse(args)
|
package/src/Package.test.ts
CHANGED
|
@@ -165,51 +165,51 @@ describe('Package.writePackageJson', () => {
|
|
|
165
165
|
test('preserves trailing newline when present', async () => {
|
|
166
166
|
const tmpDir = path.resolve(import.meta.dirname, '.tmp', crypto.randomUUID())
|
|
167
167
|
await fs.mkdir(tmpDir, { recursive: true })
|
|
168
|
-
|
|
168
|
+
|
|
169
169
|
const pkgPath = path.resolve(tmpDir, 'package.json')
|
|
170
170
|
const contentWithNewline = `{\n "name": "test",\n "version": "1.0.0"\n}\n`
|
|
171
171
|
await fs.writeFile(pkgPath, contentWithNewline, 'utf-8')
|
|
172
|
-
|
|
172
|
+
|
|
173
173
|
const pkgJson = await Package.readPackageJson({ cwd: tmpDir })
|
|
174
174
|
pkgJson.version = '1.0.1'
|
|
175
175
|
await Package.writePackageJson(tmpDir, pkgJson)
|
|
176
|
-
|
|
176
|
+
|
|
177
177
|
const result = await fs.readFile(pkgPath, 'utf-8')
|
|
178
178
|
expect(result.endsWith('\n')).toBe(true)
|
|
179
|
-
|
|
179
|
+
|
|
180
180
|
await fs.rm(tmpDir, { recursive: true })
|
|
181
181
|
})
|
|
182
182
|
|
|
183
183
|
test('preserves no trailing newline when absent', async () => {
|
|
184
184
|
const tmpDir = path.resolve(import.meta.dirname, '.tmp', crypto.randomUUID())
|
|
185
185
|
await fs.mkdir(tmpDir, { recursive: true })
|
|
186
|
-
|
|
186
|
+
|
|
187
187
|
const pkgPath = path.resolve(tmpDir, 'package.json')
|
|
188
188
|
const contentWithoutNewline = `{\n "name": "test",\n "version": "1.0.0"\n}`
|
|
189
189
|
await fs.writeFile(pkgPath, contentWithoutNewline, 'utf-8')
|
|
190
|
-
|
|
190
|
+
|
|
191
191
|
const pkgJson = await Package.readPackageJson({ cwd: tmpDir })
|
|
192
192
|
pkgJson.version = '1.0.1'
|
|
193
193
|
await Package.writePackageJson(tmpDir, pkgJson)
|
|
194
|
-
|
|
194
|
+
|
|
195
195
|
const result = await fs.readFile(pkgPath, 'utf-8')
|
|
196
196
|
expect(result.endsWith('\n')).toBe(false)
|
|
197
197
|
expect(result.endsWith('}\n')).toBe(false)
|
|
198
198
|
expect(result.endsWith('}')).toBe(true)
|
|
199
|
-
|
|
199
|
+
|
|
200
200
|
await fs.rm(tmpDir, { recursive: true })
|
|
201
201
|
})
|
|
202
202
|
|
|
203
203
|
test('defaults to trailing newline when no cache exists', async () => {
|
|
204
204
|
const tmpDir = path.resolve(import.meta.dirname, '.tmp', crypto.randomUUID())
|
|
205
205
|
await fs.mkdir(tmpDir, { recursive: true })
|
|
206
|
-
|
|
206
|
+
|
|
207
207
|
const pkgJson = { name: 'test', version: '1.0.0' }
|
|
208
208
|
await Package.writePackageJson(tmpDir, pkgJson)
|
|
209
|
-
|
|
209
|
+
|
|
210
210
|
const result = await fs.readFile(path.resolve(tmpDir, 'package.json'), 'utf-8')
|
|
211
211
|
expect(result.endsWith('\n')).toBe(true)
|
|
212
|
-
|
|
212
|
+
|
|
213
213
|
await fs.rm(tmpDir, { recursive: true })
|
|
214
214
|
})
|
|
215
215
|
})
|
package/src/Package.ts
CHANGED
|
@@ -633,10 +633,10 @@ export async function writePackageJson(cwd: string, pkgJson: PackageJson) {
|
|
|
633
633
|
const content = packageJsonCache.get(cwd)
|
|
634
634
|
const indent = content ? detectIndent(content) : ' '
|
|
635
635
|
const hasTrailingNewline = content ? content.endsWith('\n') : true
|
|
636
|
-
|
|
636
|
+
|
|
637
637
|
let output = JSON.stringify(pkgJson, null, indent)
|
|
638
638
|
if (hasTrailingNewline) output += '\n'
|
|
639
|
-
|
|
639
|
+
|
|
640
640
|
await fs.writeFile(path.resolve(cwd, 'package.json'), output, 'utf-8')
|
|
641
641
|
}
|
|
642
642
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as fs from 'node:fs'
|
|
2
|
+
import * as path from 'node:path'
|
|
1
3
|
import type { Command } from 'cac'
|
|
2
4
|
import * as Package from '../../Package.js'
|
|
3
5
|
|
|
@@ -35,3 +37,62 @@ export declare namespace build {
|
|
|
35
37
|
tsgo?: boolean | undefined
|
|
36
38
|
}
|
|
37
39
|
}
|
|
40
|
+
|
|
41
|
+
export async function preparePublish(command: Command) {
|
|
42
|
+
return command
|
|
43
|
+
.option('--cwd <directory>', 'Working directory to publish from')
|
|
44
|
+
.action(async (options: preparePublish.CommandOptions) => {
|
|
45
|
+
const { cwd = process.cwd() } = options
|
|
46
|
+
|
|
47
|
+
console.log(`→ Preparing package at ${cwd}`)
|
|
48
|
+
|
|
49
|
+
// Build the package
|
|
50
|
+
await Package.build({ cwd })
|
|
51
|
+
|
|
52
|
+
// Get the package.json path
|
|
53
|
+
const packageJsonPath = path.join(cwd, './package.json')
|
|
54
|
+
|
|
55
|
+
// Copy package.json to a temporary file
|
|
56
|
+
fs.copyFileSync(packageJsonPath, packageJsonPath.replace('.json', '.tmp.json'))
|
|
57
|
+
|
|
58
|
+
// Read package.json as text to find the marker position
|
|
59
|
+
const content = fs.readFileSync(packageJsonPath, 'utf-8')
|
|
60
|
+
const data = JSON.parse(content)
|
|
61
|
+
|
|
62
|
+
// Find all keys that appear before "[!start-pkg]" in the file
|
|
63
|
+
const keys = Object.keys(data)
|
|
64
|
+
const markerIndex = keys.indexOf('[!start-pkg]')
|
|
65
|
+
|
|
66
|
+
// Remove all keys up to and including the marker
|
|
67
|
+
const keysToRemove = keys.slice(0, markerIndex + 1)
|
|
68
|
+
for (const key of keysToRemove) delete data[key]
|
|
69
|
+
|
|
70
|
+
// Write back to package.json
|
|
71
|
+
fs.writeFileSync(packageJsonPath, `${JSON.stringify(data, null, 2)}\n`, 'utf-8')
|
|
72
|
+
|
|
73
|
+
console.log(`✔︎ Package at ${cwd} prepared successfully`)
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export declare namespace preparePublish {
|
|
78
|
+
type CommandOptions = build.CommandOptions
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export async function postPublish(command: Command) {
|
|
82
|
+
return command
|
|
83
|
+
.option('--cwd <directory>', 'Working directory to publish from')
|
|
84
|
+
.action(async (options: postPublish.CommandOptions) => {
|
|
85
|
+
const { cwd = process.cwd() } = options
|
|
86
|
+
|
|
87
|
+
const packageJsonPath = path.join(cwd, './package.json')
|
|
88
|
+
const tmpPackageJsonPath = path.join(cwd, './package.tmp.json')
|
|
89
|
+
if (fs.existsSync(tmpPackageJsonPath)) fs.renameSync(tmpPackageJsonPath, packageJsonPath)
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export declare namespace postPublish {
|
|
94
|
+
type CommandOptions = {
|
|
95
|
+
/** Working directory to publish from */
|
|
96
|
+
cwd?: string | undefined
|
|
97
|
+
}
|
|
98
|
+
}
|