tsc-after 0.5.0 → 1.0.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.
package/README.md CHANGED
@@ -1,17 +1,40 @@
1
1
  <h1 align="center">tsc-after</h1>
2
2
 
3
- <p align="center">Your <code>dist</code>, as <code>tsc</code> should've left it. 🧹</p>
3
+ <p align="center">Your <code>dist</code>, as <code>tsc</code> should've left it.</p>
4
4
 
5
5
  <p align="center">
6
6
  <a href="https://npmjs.com/package/tsc-after"><img alt="npm version" src="https://img.shields.io/npm/v/tsc-after" /></a>
7
+ <a href="https://github.com/michal-kocarek/tsc-after/actions/workflows/ci.yaml?query=branch%3Amain"><img alt="CI" src="https://img.shields.io/github/actions/workflow/status/michal-kocarek/tsc-after/ci.yaml?branch=main&label=CI" /></a>
8
+ <a href="https://scorecard.dev/viewer/?uri=github.com/michal-kocarek/tsc-after"><img alt="OpenSSF Scorecard" src="https://api.scorecard.dev/projects/github.com/michal-kocarek/tsc-after/badge" /></a>
7
9
  <a href="https://codecov.io/gh/michal-kocarek/tsc-after"><img alt="Coverage" src="https://img.shields.io/codecov/c/github/michal-kocarek/tsc-after" /></a>
8
10
  <a href="./LICENSE.md"><img alt="License: MIT" src="https://img.shields.io/badge/license-MIT-blue" /></a>
9
11
  </p>
10
12
 
11
13
  `tsc` compiles your files, but it never deletes anything.
12
- Rename `foo.ts` to `foo/index.ts`, and `dist/foo.js` lives on forever.
14
+ Rename `src/foo.ts` to `src/foo/index.ts`, and `dist/foo.js` lives on forever.
13
15
 
14
- `tsc-after` reads your `tsconfig.json`, works out which files `tsc` would emit today, and removes the stale outputs it wouldn't.
16
+ `tsc-after` reads your tsconfig, asks TypeScript which files `tsc` emits, and removes every other file in `outDir`, plus any directories left empty.
17
+ It is tested against real `tsc` output on Linux and Windows, and has no dependencies beyond the TypeScript already in your project.
18
+
19
+ ## Why not `rm -rf dist && tsc`?
20
+
21
+ Wiping `outDir` before every build (`rm -rf dist && tsc`, `rimraf dist && tsc`, or a `prebuild` script) is the usual fix for stale outputs.
22
+ On GitHub, about 274,000 `package.json` files run `rm -rf dist`, and another 199,000 run `rimraf dist` (see [`market-research.md`](./docs/market-research.md)).
23
+
24
+ `tsc-after` removes only stale outputs, so the rest of `outDir` stays in place:
25
+
26
+ - **Incremental builds.** With `incremental` or `composite`, the `.tsbuildinfo` file and unchanged outputs survive, so `tsc` re-emits only what changed.
27
+ - **Quiet file watchers.** IDEs, `node --watch`, nodemon, and test runners see only the files that changed.
28
+ - **No empty `outDir`.** Dependent packages, dev servers, and IDE type checking never see missing outputs, even mid-build or after a failed build.
29
+ With `tsc && tsc-after`, cleanup runs only after `tsc` succeeds.
30
+
31
+ ## Install
32
+
33
+ ```sh
34
+ npm install --save-dev tsc-after
35
+ ```
36
+
37
+ Release notes are in [`CHANGELOG.md`](./CHANGELOG.md).
15
38
 
16
39
  ## Usage
17
40
 
@@ -22,71 +45,68 @@ In `package.json`, replace the clean-then-compile command:
22
45
  + tsc && tsc-after
23
46
  ```
24
47
 
25
- Additional usage:
48
+ > **Important:** If another tool or a script also writes into `outDir` or `declarationDir`, `tsc-after` removes those files as stale, because `tsc` doesn't emit them.
49
+ > Point such tools at another directory, or bring single files in with `--copy`.
50
+
51
+ Try it first with `--dry`, which lists what would be removed without changing any files:
26
52
 
27
53
  ```sh
28
- # Clean after compile; run after tsc build.
29
- tsc-after
54
+ npx tsc-after --dry
55
+ ```
30
56
 
31
- # Preview planned removals for tsconfig.json.
32
- tsc-after --dry
57
+ More examples:
33
58
 
34
- # Select a tsconfig file instead of the default.
35
- tsc-after --project tsconfig.build.json
59
+ ```sh
60
+ # Clean up after a build that uses another tsconfig.
61
+ tsc -p tsconfig.build.json && tsc-after -p tsconfig.build.json
36
62
 
37
- # Select a folder with a tsconfig.json.
38
- tsc-after -p packages/core
63
+ # Remove stale outputs, then copy src/schema.json to outDir/schema.json.
64
+ tsc && tsc-after --copy src/schema.json:schema.json
39
65
  ```
40
66
 
41
- `tsc-after` asks TypeScript which files the project emits, then removes every other regular file in `outDir` and `declarationDir`, along with directories left empty.
42
- It skips symbolic links and entries on other devices inside `outDir` or `declarationDir`.
67
+ Now that `outDir` survives between builds, turn on [`incremental`](https://www.typescriptlang.org/tsconfig/#incremental) in your tsconfig, so `tsc` re-emits only what changed.
43
68
 
44
- `--dry` lists planned removals without changing files.
45
- Use `--verbose` to add individual removed and skipped entries.
69
+ ## Options
70
+
71
+ - `--project`, `-p`: Use the project given the path to its configuration file, or to a directory with a `tsconfig.json`.
72
+ - `--dry`, `-d`: Preview removals and copies without changing files.
73
+ - `--verbose`: Enable verbose logging of removed, copied, and skipped entries.
74
+ - `--copy <source>:<destination>`: Copy a file to a path relative to `outDir`.
75
+ The source is relative to the current working directory.
76
+ Repeat the flag to copy more files.
77
+ - `--noClean`: Skip cleanup and only run `--copy`.
78
+ - `--help`, `-h`: Print the help message.
79
+ - `--version`: Print the version.
46
80
 
47
81
  ## Limitations
48
82
 
49
- `tsc-after` reads your tsconfig the way `tsc` does; this list covers only where it differs.
83
+ `tsc-after` reads your tsconfig the way `tsc` does.
84
+ This list covers only where it differs.
50
85
 
51
- - `outDir` (and `declarationDir`) must hold only TypeScript outputs: anything else, including copied assets, is removed as stale.
86
+ - `--copy` copies single files, not globs or directories.
52
87
  - `outFile` is rejected, and project references are not followed.
53
- - Support for TypeScript 3.9 - 4.1 is limited, because they compute output paths differently:
54
- - `rootDir` is required ([#15](https://github.com/michal-kocarek/tsc-after/issues/15)).
55
- - 3.9 only: `emitDeclarationOnly` with `resolveJsonModule` and JSON source files, and `allowJs` with `jsx: preserve`, `declaration`, and `.jsx` source files are refused ([#15](https://github.com/michal-kocarek/tsc-after/issues/15)).
56
- - TypeScript 7.1 beta support is experimental.
88
+ - TypeScript 7.1 support follows its beta API and may change with TypeScript releases.
57
89
 
58
- Planned: `--copy`, `--exclude`, and `--watch`.
59
- See [`product.md`](./docs/product.md) for the roadmap.
90
+ ## Safety
60
91
 
61
- ## Security measures
92
+ `tsc-after` deletes files, so it is built to be predictable:
62
93
 
63
- - Cleanup is refused unless `outDir` is set and `noEmit` is disabled.
64
- - `outDir` and `declarationDir` must be inside, and not equal to, the current working directory.
65
- - Cleanup is refused when `outDir` or `declarationDir` contains a source file of the project.
66
- - Cleanup is refused when `outDir` or `declarationDir` is reached through a symbolic link.
67
- - A `--project` path outside the current working directory is refused.
68
- - Without `--project`, only `tsconfig.json` in the current working directory is read; unlike `tsc`, parent directories are not searched.
94
+ - **Checked against `tsc`.** [Tests](./src/__tests__/emittedLayouts.e2e.test.ts) compile real projects and compare what `tsc-after` keeps with `tsc --listEmittedFiles`.
95
+ - **Tested where you run it.** [CI](./.github/workflows/ci.yaml) runs every test on Linux and Windows, on the oldest release of each supported Node.js line, and on TypeScript 4.2 through 7.1 beta.
96
+ - **Published from CI.** GitHub Actions builds and publishes each release with [npm provenance](https://docs.npmjs.com/generating-provenance-statements), only after CI passes.
97
+ - **Refuses rather than guesses.** It stops before changing any file when:
98
+ - `outDir` is not set, or `noEmit` is enabled.
99
+ - `outDir` or `declarationDir` is the current working directory or outside it, contains a source file of the project, or is reached through a symbolic link.
100
+ - A `--copy` source is not a regular file inside the current working directory, or lies inside `outDir` or `declarationDir`.
101
+ - A `--copy` destination leaves `outDir`, or would be written through a symbolic link.
102
+ - The `--project` path is outside the current working directory.
103
+ - `--project` is omitted and the current working directory has no `tsconfig.json`.
104
+ Unlike `tsc`, it doesn't search parent directories.
69
105
 
70
106
  ## Requirements
71
107
 
72
- - Node.js 16.19.0 or later, including the latest LTS.
73
- - TypeScript 3.9.10 through 7.x, including 7.1 beta (except 7.0, which has no API support).
74
-
75
- ## Why not `rm -rf dist && tsc`?
76
-
77
- Wiping `outDir` before every build (`rm -rf dist && tsc`, `rimraf dist && tsc`, or a `prebuild` script) is the usual fix for stale outputs.
78
- On GitHub, about 274k `package.json` files run `rm -rf dist` and another 199k run `rimraf dist` (see [`market-research.md`](./docs/market-research.md)).
79
-
80
- `tsc-after` is intended to remove only stale outputs rather than wiping `outDir` and rebuilding everything.
81
- That brings:
82
-
83
- - Incremental builds without extra tooling: with `incremental` or `composite`, the `.tsbuildinfo` file and unchanged outputs survive, so `tsc` re-emits only what changed.
84
- - Less work for file watchers: IDEs, `tsc --watch` in dependent packages, `node --watch`, nodemon, and test runners see only the changed files instead of every output being deleted and recreated.
85
- - No missing outputs mid-build: dependent packages, running dev servers, and IDE type checking never see an empty `outDir`.
86
- - A failed build never leaves `outDir` empty: with `tsc && tsc-after`, cleanup runs only after `tsc` succeeds.
87
-
88
- **Using a bundler such as tsup, Vite, or esbuild?**<br>
89
- They already clean up after themselves, so you probably don't need `tsc-after`.
108
+ - Node.js 16.19.0 or later.
109
+ - TypeScript 4.2.4 to 6.x, or 7.1 beta to 7.x (7.0 has no API).
90
110
 
91
111
  ## Contributing
92
112
 
package/dist/tscAfter.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as util from "node:util";
2
- import path from "node:path";
3
2
  import fs from "node:fs";
3
+ import path from "node:path";
4
4
  import ts from "typescript";
5
5
  // src/common/errors.ts
6
6
  /** Error whose message is human-readable and printed to the user without a stack trace. */
@@ -29,15 +29,21 @@ const cliArgsOptions = {
29
29
  },
30
30
  project: {
31
31
  default: "tsconfig.json",
32
- helpDescription: "Use the project given the path to its configuration file, or to a folder with a 'tsconfig.json'.",
32
+ helpDescription: "Use the project given the path to its configuration file, or to a directory with a 'tsconfig.json'.",
33
33
  short: "p",
34
34
  type: "string"
35
35
  },
36
36
  noClean: {
37
37
  default: false,
38
- helpDescription: "Disable removing stale outputs from 'outDir'.",
38
+ helpDescription: "Skip cleanup and only run '--copy'.",
39
39
  type: "boolean"
40
40
  },
41
+ copy: {
42
+ default: [],
43
+ helpDescription: "Copy a file to a path relative to 'outDir', given as '<source>:<destination>'.",
44
+ multiple: true,
45
+ type: "string"
46
+ },
41
47
  dry: {
42
48
  default: false,
43
49
  helpDescription: "Show what would be deleted.",
@@ -50,6 +56,159 @@ const cliArgsOptions = {
50
56
  type: "boolean"
51
57
  }
52
58
  };
59
+ // src/common/paths.ts
60
+ function displayPath(cwd, filePath) {
61
+ return path.relative(cwd, filePath) || ".";
62
+ }
63
+ function isPathInside(dirPath, filePath, useCaseSensitiveFileNames) {
64
+ const normalizedDirPath = normalizePathForComparison(dirPath, useCaseSensitiveFileNames);
65
+ const normalizedFilePath = normalizePathForComparison(filePath, useCaseSensitiveFileNames);
66
+ return normalizedDirPath === normalizedFilePath || normalizedFilePath.startsWith(ensureTrailingDirectorySeparator(normalizedDirPath));
67
+ }
68
+ function lstatIfExists(filePath) {
69
+ try {
70
+ return fs.lstatSync(filePath);
71
+ } catch (error) {
72
+ if (isNodeErrorOf(error, Error, "ENOENT") || isNodeErrorOf(error, Error, "ENOTDIR")) return;
73
+ throw error;
74
+ }
75
+ }
76
+ function normalizedAncestorDirPaths(filePath, rootPath, useCaseSensitiveFileNames) {
77
+ const normalizedRootPath = normalizePathForComparison(rootPath, useCaseSensitiveFileNames);
78
+ const rootPathPrefix = ensureTrailingDirectorySeparator(normalizedRootPath);
79
+ const ancestorDirPaths = [];
80
+ let dirPath = path.dirname(filePath);
81
+ while (dirPath !== void 0) {
82
+ const normalizedDirPath = normalizePathForComparison(dirPath, useCaseSensitiveFileNames);
83
+ if (normalizedDirPath !== normalizedRootPath && !normalizedDirPath.startsWith(rootPathPrefix)) break;
84
+ ancestorDirPaths.push(normalizedDirPath);
85
+ if (normalizedDirPath === normalizedRootPath) break;
86
+ const parentDirPath = path.dirname(dirPath);
87
+ dirPath = parentDirPath === dirPath ? void 0 : parentDirPath;
88
+ }
89
+ return ancestorDirPaths;
90
+ }
91
+ function normalizePathForComparison(filePath, useCaseSensitiveFileNames) {
92
+ const normalizedPath = path.resolve(filePath);
93
+ return useCaseSensitiveFileNames ? normalizedPath : normalizedPath.toLowerCase();
94
+ }
95
+ function ensureTrailingDirectorySeparator(filePath) {
96
+ return filePath.endsWith(path.sep) ? filePath : `${filePath}${path.sep}`;
97
+ }
98
+ /**
99
+ * Uses the native realpath implementation to match TypeScript's canonical
100
+ * paths, including Windows 8.3 names and junctions.
101
+ */
102
+ function realpath(filePath) {
103
+ return fs.realpathSync.native(filePath);
104
+ }
105
+ // src/common/copy.ts
106
+ function parseCopyEntry(value) {
107
+ const separator = value.lastIndexOf(":");
108
+ if (separator <= 0 || separator === value.length - 1) return;
109
+ return {
110
+ destination: value.slice(separator + 1),
111
+ source: value.slice(0, separator)
112
+ };
113
+ }
114
+ /**
115
+ * Validates every entry without changing files and plans copies that are needed.
116
+ * `cwd` must be a real path.
117
+ */
118
+ function planCopy(entries, project, roots, cwd) {
119
+ const { outDir, useCaseSensitiveFileNames } = project;
120
+ const resolvedEntries = entries.map((entry) => {
121
+ return {
122
+ destinationPath: resolveDestination(entry, outDir, useCaseSensitiveFileNames, cwd),
123
+ entry
124
+ };
125
+ });
126
+ assertDestinationsDoNotConflict(resolvedEntries.map(({ destinationPath }) => destinationPath), project.outputPaths, outDir, useCaseSensitiveFileNames, cwd);
127
+ return resolvedEntries.map(({ destinationPath, entry: { source } }) => {
128
+ const { sourcePath, sourceStat } = validateSource(source, roots, cwd, useCaseSensitiveFileNames);
129
+ if (validateDestinationPath(outDir, destinationPath, cwd)?.size === sourceStat.size && fs.readFileSync(sourcePath).equals(fs.readFileSync(destinationPath))) return {
130
+ destinationPath,
131
+ reason: "up to date",
132
+ sourcePath,
133
+ type: "skipped"
134
+ };
135
+ return {
136
+ destinationPath,
137
+ sourcePath,
138
+ type: "copyFile"
139
+ };
140
+ });
141
+ }
142
+ /** Creates parent directories and copies planned files unless this is a dry run. */
143
+ function applyCopy(plan, { dry }) {
144
+ if (dry) return;
145
+ for (const verdict of plan) if (verdict.type === "copyFile") {
146
+ fs.mkdirSync(path.dirname(verdict.destinationPath), { recursive: true });
147
+ fs.copyFileSync(verdict.sourcePath, verdict.destinationPath);
148
+ }
149
+ }
150
+ function assertDestinationsDoNotConflict(destinationPaths, outputPaths, outDir, useCaseSensitiveFileNames, cwd) {
151
+ const normalizedOutputPaths = new Set([...outputPaths].map((outputPath) => normalizePathForComparison(outputPath, useCaseSensitiveFileNames)));
152
+ const normalizedOutputAncestorPaths = new Set([...outputPaths].flatMap((outputPath) => normalizedAncestorDirPaths(outputPath, outDir, useCaseSensitiveFileNames)));
153
+ const normalizedDestinations = /* @__PURE__ */ new Set();
154
+ const normalizedDestinationAncestorPaths = /* @__PURE__ */ new Set();
155
+ for (const destinationPath of destinationPaths) {
156
+ const normalizedDestinationPath = normalizePathForComparison(destinationPath, useCaseSensitiveFileNames);
157
+ const normalizedAncestors = normalizedAncestorDirPaths(destinationPath, outDir, useCaseSensitiveFileNames);
158
+ if (normalizedDestinations.has(normalizedDestinationPath)) throw refusingCopyTo(displayPath(cwd, destinationPath), "it is shared with another copy entry");
159
+ if (normalizedDestinationAncestorPaths.has(normalizedDestinationPath) || normalizedAncestors.some((ancestorPath) => normalizedDestinations.has(ancestorPath))) throw refusingCopyTo(displayPath(cwd, destinationPath), "it is nested with another copy destination");
160
+ const isOutput = normalizedOutputPaths.has(normalizedDestinationPath);
161
+ if (isOutput || normalizedOutputAncestorPaths.has(normalizedDestinationPath) || normalizedAncestors.some((ancestorPath) => normalizedOutputPaths.has(ancestorPath))) throw refusingCopyTo(displayPath(cwd, destinationPath), isOutput ? "it is an output of the project" : "it overlaps an output of the project");
162
+ normalizedDestinations.add(normalizedDestinationPath);
163
+ for (const ancestorPath of normalizedAncestors) normalizedDestinationAncestorPaths.add(ancestorPath);
164
+ }
165
+ }
166
+ function refusingCopySource(source, reason) {
167
+ return new UserError(`Refusing to copy '${source}': ${reason}.`);
168
+ }
169
+ function refusingCopyTo(destination, reason) {
170
+ return new UserError(`Refusing to copy to '${destination}': ${reason}.`);
171
+ }
172
+ function resolveDestination({ destination }, outDir, useCaseSensitiveFileNames, cwd) {
173
+ if (path.isAbsolute(destination)) throw refusingCopyTo(destination, "destination must be relative to outDir");
174
+ if (destination.split(/[/\\]/u).includes("..")) throw refusingCopyTo(destination, "destination must not contain '..'");
175
+ if (destination.endsWith("/") || destination.endsWith("\\")) throw refusingCopyTo(destination, "destination must be a file path");
176
+ const destinationPath = path.resolve(outDir, destination);
177
+ if (normalizePathForComparison(destinationPath, useCaseSensitiveFileNames) === normalizePathForComparison(outDir, useCaseSensitiveFileNames)) throw refusingCopyTo(displayPath(cwd, destinationPath), "it resolves to outDir");
178
+ if (!isPathInside(outDir, destinationPath, useCaseSensitiveFileNames)) throw refusingCopyTo(displayPath(cwd, destinationPath), "destination must be inside outDir");
179
+ return destinationPath;
180
+ }
181
+ function validateDestinationPath(outDir, destinationPath, cwd) {
182
+ const components = path.relative(outDir, destinationPath).split(path.sep).filter(Boolean);
183
+ let currentPath = outDir;
184
+ for (const component of components.slice(0, -1)) {
185
+ currentPath = path.join(currentPath, component);
186
+ const stat = lstatIfExists(currentPath);
187
+ if (stat === void 0) break;
188
+ if (stat.isSymbolicLink()) throw refusingCopyTo(displayPath(cwd, destinationPath), `path component '${displayPath(cwd, currentPath)}' is a symbolic link`);
189
+ if (!stat.isDirectory()) throw refusingCopyTo(displayPath(cwd, destinationPath), `path component '${displayPath(cwd, currentPath)}' is not a directory`);
190
+ }
191
+ const destinationStat = lstatIfExists(destinationPath);
192
+ if (destinationStat?.isSymbolicLink() === true) throw refusingCopyTo(displayPath(cwd, destinationPath), "it is a symbolic link");
193
+ if (destinationStat !== void 0 && !destinationStat.isFile()) throw refusingCopyTo(displayPath(cwd, destinationPath), "it is not a regular file");
194
+ return destinationStat;
195
+ }
196
+ function validateSource(source, roots, cwd, useCaseSensitiveFileNames) {
197
+ const sourcePath = path.resolve(cwd, source);
198
+ const sourceDisplayPath = displayPath(cwd, sourcePath);
199
+ if (!isPathInside(cwd, sourcePath, useCaseSensitiveFileNames)) throw refusingCopySource(sourceDisplayPath, "it is outside the current working directory");
200
+ const sourceStat = lstatIfExists(sourcePath);
201
+ if (sourceStat === void 0) throw refusingCopySource(sourceDisplayPath, "it does not exist");
202
+ if (sourceStat.isSymbolicLink()) throw refusingCopySource(sourceDisplayPath, "it is a symbolic link");
203
+ if (!sourceStat.isFile()) throw refusingCopySource(sourceDisplayPath, "it is not a regular file");
204
+ const sourceRealPath = realpath(sourcePath);
205
+ if (!isPathInside(cwd, sourceRealPath, useCaseSensitiveFileNames)) throw refusingCopySource(sourceDisplayPath, "its real path is outside the current working directory");
206
+ for (const root of roots) if (isPathInside(root.path, sourcePath, useCaseSensitiveFileNames) || isPathInside(root.path, sourceRealPath, useCaseSensitiveFileNames)) throw refusingCopySource(sourceDisplayPath, `it is inside ${root.name} '${displayPath(cwd, root.path)}'`);
207
+ return {
208
+ sourcePath,
209
+ sourceStat
210
+ };
211
+ }
53
212
  // src/common/util.ts
54
213
  const EXIT_CODE_ERROR = 1;
55
214
  const EXIT_CODE_INVALID_ARGUMENTS = 2;
@@ -74,22 +233,36 @@ const PARSE_ARGS_ERROR_CODES = [
74
233
  "ERR_PARSE_ARGS_INVALID_OPTION_VALUE"
75
234
  ];
76
235
  function parseArgs(args) {
236
+ const parsed = parseNodeArgs(args);
237
+ if (parsed.values.noClean && parsed.values.copy.length === 0) throw invalidArgument("Option '--noClean' cannot be specified without specifying option '--copy'.");
238
+ const copyEntries = parsed.values.copy.map((value) => {
239
+ const entry = parseCopyEntry(value);
240
+ if (entry === void 0) throw invalidArgument(`Option '--copy' expects '<source>:<destination>', got '${value}'.`);
241
+ return entry;
242
+ });
243
+ return {
244
+ ...parsed,
245
+ copyEntries
246
+ };
247
+ }
248
+ function invalidArgument(message) {
249
+ process.exitCode = EXIT_CODE_INVALID_ARGUMENTS;
250
+ return new UserError(message);
251
+ }
252
+ function isParseArgsError(error) {
253
+ return PARSE_ARGS_ERROR_CODES.some((code) => isNodeErrorOf(error, TypeError, code));
254
+ }
255
+ function parseNodeArgs(args) {
77
256
  try {
78
257
  return util.parseArgs({
79
258
  args,
80
259
  options: cliArgsOptions
81
260
  });
82
261
  } catch (error) {
83
- if (isParseArgsError(error)) {
84
- process.exitCode = EXIT_CODE_INVALID_ARGUMENTS;
85
- throw new UserError(error.message.endsWith(".") ? error.message : `${error.message}.`);
86
- }
262
+ if (isParseArgsError(error)) throw invalidArgument(error.message.endsWith(".") ? error.message : `${error.message}.`);
87
263
  throw error;
88
264
  }
89
265
  }
90
- function isParseArgsError(error) {
91
- return PARSE_ARGS_ERROR_CODES.some((code) => isNodeErrorOf(error, TypeError, code));
92
- }
93
266
  // src/tasks/help.ts
94
267
  const FLAG_INDENT = 2;
95
268
  const FLAG_GAP = " ";
@@ -107,28 +280,12 @@ function help() {
107
280
  heading("COMMON COMMANDS"),
108
281
  command(`tsc && ${binName}`, "Removes stale outputs of the current project (tsconfig.json in the working directory)."),
109
282
  command(`${binName} -p ./path/to/tsconfig.json`, "Removes stale outputs of the TypeScript project located at the specified path."),
283
+ command(`${binName} --copy src/schema.json:schema.json`, "Removes stale outputs, then copies a file into 'outDir'."),
110
284
  command(`${binName} --dry`, "Shows what would be deleted from 'outDir', without deleting anything."),
111
285
  heading("COMMAND LINE FLAGS"),
112
286
  ...flags.map(({ description, name }) => flag(name, description))
113
287
  ].join("\n\n"));
114
288
  }
115
- // src/common/paths.ts
116
- function isPathInside(dirPath, filePath, useCaseSensitiveFileNames) {
117
- const normalizedDirPath = normalizePathForComparison(dirPath, useCaseSensitiveFileNames);
118
- const normalizedFilePath = normalizePathForComparison(filePath, useCaseSensitiveFileNames);
119
- return normalizedDirPath === normalizedFilePath || normalizedFilePath.startsWith(normalizedDirPath.endsWith(path.sep) ? normalizedDirPath : `${normalizedDirPath}${path.sep}`);
120
- }
121
- function normalizePathForComparison(filePath, useCaseSensitiveFileNames) {
122
- const normalizedPath = path.resolve(filePath);
123
- return useCaseSensitiveFileNames ? normalizedPath : normalizedPath.toLowerCase();
124
- }
125
- /**
126
- * Uses the native realpath implementation to match TypeScript's canonical
127
- * paths, including Windows 8.3 names and junctions.
128
- */
129
- function realpath(filePath) {
130
- return fs.realpathSync.native(filePath);
131
- }
132
289
  // src/common/cleanup.ts
133
290
  /**
134
291
  * Plans the removal of stale outputs from each cleanup root without changing
@@ -136,16 +293,27 @@ function realpath(filePath) {
136
293
  * A path inside outDir always belongs to outDir, even when outDir is nested in
137
294
  * declarationDir.
138
295
  */
139
- function planCleanup(project, cwd) {
296
+ function planCleanup(project, roots, copyDestinations) {
140
297
  const { outDir, useCaseSensitiveFileNames } = project;
141
298
  const normalizedOutputPaths = new Set([...project.outputPaths].map((filePath) => normalizePathForComparison(filePath, useCaseSensitiveFileNames)));
142
- const isOutputPath = (filePath) => normalizedOutputPaths.has(normalizePathForComparison(filePath, useCaseSensitiveFileNames));
299
+ const normalizedCopyDestinations = new Set(copyDestinations.map((filePath) => normalizePathForComparison(filePath, useCaseSensitiveFileNames)));
300
+ const normalizedCopyDestinationDirs = new Set(copyDestinations.flatMap((filePath) => normalizedAncestorDirPaths(filePath, outDir, useCaseSensitiveFileNames)));
301
+ const isCopyDestinationDir = (dirPath) => normalizedCopyDestinationDirs.has(normalizePathForComparison(dirPath, useCaseSensitiveFileNames));
302
+ const getKeepReason = (filePath) => {
303
+ const normalizedPath = normalizePathForComparison(filePath, useCaseSensitiveFileNames);
304
+ if (normalizedCopyDestinations.has(normalizedPath)) return "copy destination";
305
+ if (normalizedOutputPaths.has(normalizedPath)) return "expected output file";
306
+ };
143
307
  let outDirIsRemoved = false;
144
308
  const plan = [];
145
- for (const root of resolveCleanupRoots(project, cwd)) {
146
- const verdicts = readCleanupRoot(root.path, isOutputPath, (dirPath) => {
147
- if (root.name === "outDir" || !isPathInside(outDir, dirPath, useCaseSensitiveFileNames)) return;
148
- return outDirIsRemoved;
309
+ for (const root of roots) {
310
+ const verdicts = readCleanupRoot(root.path, {
311
+ getKeepReason,
312
+ isCopyDestinationDir,
313
+ isDirOwnedElsewhere: (dirPath) => {
314
+ if (root.name === "outDir" || !isPathInside(outDir, dirPath, useCaseSensitiveFileNames)) return;
315
+ return outDirIsRemoved;
316
+ }
149
317
  });
150
318
  if (root.name === "outDir") outDirIsRemoved = verdicts.some((verdict) => verdict.type === "removeDir" && verdict.path === root.path);
151
319
  plan.push({
@@ -155,10 +323,6 @@ function planCleanup(project, cwd) {
155
323
  }
156
324
  return plan;
157
325
  }
158
- /**
159
- * Removes what the plan marks for removal, contents before their directories.
160
- * Returns the plan's verdicts, with a busy cleanup root reported as skipped.
161
- */
162
326
  function applyCleanup(plan, { dry }) {
163
327
  return plan.map(({ root, verdicts }) => ({
164
328
  root,
@@ -186,6 +350,41 @@ function applyCleanup(plan, { dry }) {
186
350
  })
187
351
  }));
188
352
  }
353
+ function resolveCleanupRoots(project, cwd) {
354
+ const { declarationDir, outDir, useCaseSensitiveFileNames } = project;
355
+ const roots = [{
356
+ name: "outDir",
357
+ path: outDir,
358
+ relativePath: displayPath(cwd, outDir)
359
+ }];
360
+ if (declarationDir !== void 0) roots.push({
361
+ name: "declarationDir",
362
+ path: declarationDir,
363
+ relativePath: displayPath(cwd, declarationDir)
364
+ });
365
+ for (const root of roots) {
366
+ if (!isPathInside(cwd, root.path, useCaseSensitiveFileNames) || isPathInside(root.path, cwd, useCaseSensitiveFileNames)) throw new UserError(`Refusing to traverse outside safe paths containing tsconfig to process ${root.name}.`);
367
+ let componentPath = cwd;
368
+ for (const component of root.relativePath.split(path.sep)) {
369
+ componentPath = path.join(componentPath, component);
370
+ const stat = lstatIfExists(componentPath);
371
+ if (stat === void 0) break;
372
+ if (stat.isSymbolicLink()) throw new UserError(`Refusing to clean ${root.name} through a symbolic link: ${root.relativePath}.`);
373
+ if (!stat.isDirectory()) throw new UserError(notADirectoryError(root, displayPath(cwd, componentPath)));
374
+ }
375
+ for (const file of project.sourceFileNames) {
376
+ const filePath = path.resolve(cwd, file);
377
+ let realFilePath = filePath;
378
+ try {
379
+ realFilePath = realpath(filePath);
380
+ } catch (error) {
381
+ if (!isNodeErrorOf(error, Error, "ENOENT")) throw error;
382
+ }
383
+ if (isPathInside(root.path, filePath, useCaseSensitiveFileNames) || isPathInside(root.path, realFilePath, useCaseSensitiveFileNames)) throw new UserError(`Refusing to clean ${root.name} '${root.relativePath}': it contains source file '${displayPath(cwd, file)}'.`);
384
+ }
385
+ }
386
+ return roots.filter((root) => root.name === "outDir" || !isPathInside(outDir, root.path, useCaseSensitiveFileNames));
387
+ }
189
388
  function notADirectoryError(root, componentPath) {
190
389
  return `Refusing to clean ${root.name} '${root.relativePath}': '${componentPath}' is not a directory.`;
191
390
  }
@@ -194,13 +393,8 @@ function notADirectoryError(root, componentPath) {
194
393
  * `isDirOwnedElsewhere` returns `undefined` for a directory this root owns, or
195
394
  * whether another root's plan removes it.
196
395
  */
197
- function readCleanupRoot(rootPath, isOutputPath, isDirOwnedElsewhere) {
198
- try {
199
- fs.lstatSync(rootPath);
200
- } catch (error) {
201
- if (isNodeErrorOf(error, Error, "ENOENT")) return [];
202
- throw error;
203
- }
396
+ function readCleanupRoot(rootPath, { getKeepReason, isCopyDestinationDir, isDirOwnedElsewhere }) {
397
+ if (lstatIfExists(rootPath) === void 0) return [];
204
398
  return readDir(rootPath);
205
399
  function readDir(dirPath) {
206
400
  const verdicts = [];
@@ -229,10 +423,11 @@ function readCleanupRoot(rootPath, isOutputPath, isDirOwnedElsewhere) {
229
423
  continue;
230
424
  }
231
425
  if (fullPathStat.isFile()) {
232
- if (isOutputPath(fullPath)) {
426
+ const keepReason = getKeepReason(fullPath);
427
+ if (keepReason !== void 0) {
233
428
  verdicts.push({
234
429
  path: fullPath,
235
- reason: "expected output file",
430
+ reason: keepReason,
236
431
  type: "skipped"
237
432
  });
238
433
  dirIsEmpty = false;
@@ -262,7 +457,12 @@ function readCleanupRoot(rootPath, isOutputPath, isDirOwnedElsewhere) {
262
457
  });
263
458
  dirIsEmpty = false;
264
459
  }
265
- if (dirIsEmpty) verdicts.push({
460
+ if (isCopyDestinationDir(dirPath)) verdicts.push({
461
+ path: dirPath,
462
+ reason: "copy destination directory",
463
+ type: "skipped"
464
+ });
465
+ else if (dirIsEmpty) verdicts.push({
266
466
  path: dirPath,
267
467
  type: "removeDir"
268
468
  });
@@ -274,48 +474,6 @@ function readCleanupRoot(rootPath, isOutputPath, isDirOwnedElsewhere) {
274
474
  return verdicts;
275
475
  }
276
476
  }
277
- function resolveCleanupRoots(project, cwd) {
278
- const { declarationDir, outDir, useCaseSensitiveFileNames } = project;
279
- const roots = [{
280
- name: "outDir",
281
- path: outDir,
282
- relativePath: path.relative(cwd, outDir)
283
- }];
284
- if (declarationDir !== void 0) roots.push({
285
- name: "declarationDir",
286
- path: declarationDir,
287
- relativePath: path.relative(cwd, declarationDir)
288
- });
289
- for (const root of roots) {
290
- if (!isPathInside(cwd, root.path, useCaseSensitiveFileNames) || isPathInside(root.path, cwd, useCaseSensitiveFileNames)) throw new UserError(`Refusing to traverse outside safe paths containing tsconfig to process ${root.name}!`);
291
- let componentPath = cwd;
292
- for (const component of root.relativePath.split(path.sep)) {
293
- componentPath = path.join(componentPath, component);
294
- let stat;
295
- try {
296
- stat = fs.lstatSync(componentPath);
297
- } catch (error) {
298
- if (isNodeErrorOf(error, Error, "ENOENT")) break;
299
- throw error;
300
- }
301
- if (stat.isSymbolicLink()) throw new UserError(`Refusing to clean ${root.name} through a symbolic link: ${root.relativePath}!`);
302
- if (!stat.isDirectory()) throw new UserError(notADirectoryError(root, path.relative(cwd, componentPath)));
303
- }
304
- for (const file of project.sourceFileNames) {
305
- const filePath = path.resolve(cwd, file);
306
- let realFilePath = filePath;
307
- try {
308
- realFilePath = realpath(filePath);
309
- } catch (error) {
310
- if (!isNodeErrorOf(error, Error, "ENOENT")) throw error;
311
- }
312
- if (isPathInside(root.path, filePath, useCaseSensitiveFileNames) || isPathInside(root.path, realFilePath, useCaseSensitiveFileNames)) throw new UserError(`Refusing to clean ${root.name} '${root.relativePath}': it contains source file '${path.relative(cwd, file)}'.`);
313
- }
314
- }
315
- return roots.filter((root) => root.name === "outDir" || !isPathInside(outDir, root.path, useCaseSensitiveFileNames));
316
- }
317
- const TYPESCRIPT_4_0 = 4e6;
318
- const TYPESCRIPT_4_2 = 4002e3;
319
477
  function parseTypeScriptVersion(version) {
320
478
  const match = /^(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)(?:-[-.0-9A-Za-z]+)?(?:\+[-.0-9A-Za-z]+)?$/u.exec(version);
321
479
  if (match?.groups === void 0) return NaN;
@@ -326,17 +484,17 @@ const typescriptVersion = parseTypeScriptVersion(ts.version);
326
484
  // src/common/typescript/loadCompiler.ts
327
485
  async function loadCompiler() {
328
486
  if (Number.isNaN(typescriptVersion)) throw new UserError(`Cannot parse TypeScript version '${ts.version}'.`);
329
- if (typescriptVersion < 3009e3) throw new UserError("TypeScript 3.8 and earlier are not supported. Use TypeScript 3.9 or later.");
487
+ if (typescriptVersion < 4002e3) throw new UserError("TypeScript 4.1 and earlier are not supported. Use TypeScript 4.2 or later.");
330
488
  if (typescriptVersion < 7e6) {
331
- const { TypeScriptPre7Compiler } = await import("./typescriptPre7Compiler-CZ1GIAWf.js");
489
+ const { TypeScriptPre7Compiler } = await import("./typescriptPre7Compiler-By2mX1Hw.js");
332
490
  return new TypeScriptPre7Compiler();
333
491
  }
334
492
  if (typescriptVersion < 7001e3) throw new UserError("TypeScript 7.0 is not supported. Use TypeScript 7.1 or later.");
335
- const { TypeScript7Compiler } = await import("./typescript7Compiler-D6FwNrdQ.js");
493
+ const { TypeScript7Compiler } = await import("./typescript7Compiler-B48Ljxkl.js");
336
494
  return TypeScript7Compiler.create();
337
495
  }
338
496
  // src/common/project.ts
339
- const OUTSIDE_CWD_ERROR = "Refusing to traverse outside current working directory to read tsconfig!";
497
+ const OUTSIDE_CWD_ERROR = "Refusing to traverse outside current working directory to read tsconfig.";
340
498
  const NO_EMIT_ERROR = "Refusing to clean outDir because noEmit is enabled.";
341
499
  const MISSING_OUT_DIR_ERROR = "outDir is not set in tsconfig.json; tsc-after only cleans a dedicated outDir. Set compilerOptions.outDir, e.g. \"dist\".";
342
500
  const DECLARATION_DISABLED_ERROR = "Refusing to clean declarationDir because declaration is not enabled.";
@@ -372,8 +530,8 @@ function resolveConfigFilePath(compiler, projectPath, cwd) {
372
530
  }
373
531
  function resolveOutputDirs({ options }, cwd) {
374
532
  if (options.noEmit === true) throw new UserError(NO_EMIT_ERROR);
375
- if (options.outFile !== void 0) throw new UserError("outFile is not supported");
376
- if (options.project !== void 0) throw new UserError("Project mode is not supported");
533
+ if (options.outFile !== void 0) throw new UserError("outFile is not supported.");
534
+ if (options.project !== void 0) throw new UserError("Project mode is not supported.");
377
535
  if (options.outDir === void 0) throw new UserError(MISSING_OUT_DIR_ERROR);
378
536
  if (options.declarationDir !== void 0 && options.declaration !== true && options.composite !== true) throw new UserError(DECLARATION_DISABLED_ERROR);
379
537
  return {
@@ -382,47 +540,108 @@ function resolveOutputDirs({ options }, cwd) {
382
540
  };
383
541
  }
384
542
  // src/tasks/mainAction.ts
543
+ const verbs = {
544
+ dry: {
545
+ copy: "Would copy",
546
+ remove: "Would remove",
547
+ removeAfterCopy: "remove"
548
+ },
549
+ past: {
550
+ copy: "Copied",
551
+ remove: "Removed",
552
+ removeAfterCopy: "removed"
553
+ }
554
+ };
385
555
  async function mainAction(args) {
386
556
  const cwd = realpath(process.cwd());
387
557
  const project = await loadProject(args.values.project, cwd);
388
- print(`Using tsconfig: ${path.relative(cwd, project.configFilePath)}`);
389
- const plan = planCleanup(project, cwd);
390
- if (args.values.noClean) return;
558
+ print(`Using tsconfig: ${displayPath(cwd, project.configFilePath)}`);
559
+ const roots = resolveCleanupRoots(project, cwd);
560
+ const copyPlan = planCopy(args.copyEntries, project, roots, cwd);
561
+ const cleanupPlan = planCleanup(project, roots, copyPlan.map(({ destinationPath }) => destinationPath));
391
562
  const { dry, verbose } = args.values;
392
- const results = applyCleanup(plan, { dry });
393
- const removeVerb = dry ? "Would remove" : "Removed";
394
- for (const { root, verdicts } of results) {
395
- let fileCount = 0;
396
- let dirCount = 0;
397
- for (const verdict of verdicts) {
398
- const displayPath = path.relative(cwd, verdict.path);
399
- switch (verdict.type) {
400
- case "removeDir":
401
- dirCount++;
402
- if (dry || verbose) print(`${removeVerb} empty directory: ${displayPath}`);
403
- break;
404
- case "removeFile":
405
- fileCount++;
406
- if (dry || verbose) print(`${removeVerb} file: ${displayPath}`);
407
- break;
408
- case "skipped":
409
- if (verbose) print(`Skipped (${verdict.reason}): ${displayPath}`);
410
- break;
411
- default: assertUnreachable(verdict);
412
- }
413
- }
414
- const parts = [];
415
- if (fileCount > 0) parts.push(formatCount(fileCount, "file", "files"));
416
- if (dirCount > 0) parts.push(formatCount(dirCount, "empty directory", "empty directories"));
417
- if (parts.length > 0) print(`${binName}: ${removeVerb} ${parts.join(" and ")} from ${styleText("italic", root.relativePath)}`);
418
- else if (dry || results.length > 1) print(`${binName}: Nothing to remove from ${styleText("italic", root.relativePath)}`);
419
- }
563
+ const cleanupResults = args.values.noClean ? [] : applyCleanup(cleanupPlan, { dry });
564
+ applyCopy(copyPlan, { dry });
565
+ reportCleanupVerdicts(cleanupResults, cwd, {
566
+ dry,
567
+ verbose
568
+ });
569
+ reportCopyVerdicts(copyPlan, cwd, {
570
+ dry,
571
+ verbose
572
+ });
573
+ reportSummaries(roots, cleanupResults, copyPlan, {
574
+ dry,
575
+ noClean: args.values.noClean
576
+ });
420
577
  }
421
578
  function formatCount(count, singular, plural) {
422
579
  return `${count.toFixed()} ${count === 1 ? singular : plural}`;
423
580
  }
581
+ function getNothingToDoLabel(root, noClean, hasCopyEntries) {
582
+ if (noClean) return "Nothing to copy to";
583
+ if (root.name === "outDir" && hasCopyEntries) return "Nothing to copy or remove from";
584
+ return "Nothing to remove from";
585
+ }
586
+ function reportCleanupVerdicts(results, cwd, { dry, verbose }) {
587
+ const removeVerb = verbs[dry ? "dry" : "past"].remove;
588
+ for (const { verdicts } of results) for (const verdict of verdicts) {
589
+ const verdictPath = displayPath(cwd, verdict.path);
590
+ switch (verdict.type) {
591
+ case "removeDir":
592
+ if (dry || verbose) print(`${removeVerb} empty directory: ${verdictPath}`);
593
+ break;
594
+ case "removeFile":
595
+ if (dry || verbose) print(`${removeVerb} file: ${verdictPath}`);
596
+ break;
597
+ case "skipped":
598
+ if (verbose) print(`Skipped (${verdict.reason}): ${verdictPath}`);
599
+ break;
600
+ default: assertUnreachable(verdict);
601
+ }
602
+ }
603
+ }
604
+ function reportCopyVerdicts(results, cwd, { dry, verbose }) {
605
+ for (const verdict of results) {
606
+ const sourcePath = displayPath(cwd, verdict.sourcePath);
607
+ const destinationPath = displayPath(cwd, verdict.destinationPath);
608
+ if (verdict.type === "copyFile") {
609
+ if (dry || verbose) print(`${verbs[dry ? "dry" : "past"].copy} file: ${sourcePath} -> ${destinationPath}`);
610
+ } else if (verbose) print(`Skipped (up to date): ${sourcePath} -> ${destinationPath}`);
611
+ }
612
+ }
613
+ function reportSummaries(roots, cleanupResults, copyResults, { dry, noClean }) {
614
+ const actionVerbs = verbs[dry ? "dry" : "past"];
615
+ const hasCopyEntries = copyResults.length > 0;
616
+ const cleanupResultsByRoot = new Map(cleanupResults.map(({ root, verdicts }) => [root.path, verdicts]));
617
+ for (const root of roots) {
618
+ if (noClean && root.name !== "outDir") continue;
619
+ const copyCount = root.name === "outDir" ? copyResults.filter(({ type }) => type === "copyFile").length : 0;
620
+ const verdicts = cleanupResultsByRoot.get(root.path) ?? [];
621
+ const fileCount = verdicts.filter(({ type }) => type === "removeFile").length;
622
+ const dirCount = verdicts.filter(({ type }) => type === "removeDir").length;
623
+ const removeParts = [];
624
+ if (fileCount > 0) removeParts.push(formatCount(fileCount, "file", "files"));
625
+ if (dirCount > 0) removeParts.push(formatCount(dirCount, "empty directory", "empty directories"));
626
+ const actionParts = [];
627
+ if (copyCount > 0) actionParts.push(`${actionVerbs.copy} ${formatCount(copyCount, "file", "files")}`);
628
+ if (!noClean && removeParts.length > 0) {
629
+ const removeVerb = copyCount > 0 ? actionVerbs.removeAfterCopy : actionVerbs.remove;
630
+ actionParts.push(`${removeVerb} ${removeParts.join(" and ")}`);
631
+ }
632
+ if (actionParts.length === 0) {
633
+ if (dry || roots.length > 1) {
634
+ const nothingToDo = getNothingToDoLabel(root, noClean, hasCopyEntries);
635
+ print(`${binName}: ${nothingToDo} ${styleText("italic", root.relativePath)}`);
636
+ }
637
+ continue;
638
+ }
639
+ const preposition = copyCount > 0 && removeParts.length === 0 ? "to" : "from";
640
+ print(`${binName}: ${actionParts.join(" and ")} ${preposition} ${styleText("italic", root.relativePath)}`);
641
+ }
642
+ }
424
643
  // package.json
425
- var version$1 = "0.5.0";
644
+ var version$1 = "1.0.1";
426
645
  // src/tasks/version.ts
427
646
  function version() {
428
647
  print(`${binName}/${version$1} ${process.platform}-${process.arch} node-${process.versions.node} typescript-${ts.version}`);
@@ -440,4 +659,4 @@ async function main() {
440
659
  }
441
660
  }
442
661
  main();
443
- export { UserError as i, TYPESCRIPT_4_2 as n, typescriptVersion as r, TYPESCRIPT_4_0 as t };
662
+ export { UserError as t };
@@ -1,5 +1,5 @@
1
1
  import fs from "node:fs";
2
- import { i as UserError } from "./tscAfter.js";
2
+ import { t as UserError } from "./tscAfter.js";
3
3
  import path from "node:path";
4
4
  // src/common/typescript/outputPaths.ts
5
5
  const declarationFileExtensions = [
@@ -1,7 +1,7 @@
1
1
  import ts from "typescript";
2
- import { i as UserError, r as typescriptVersion } from "./tscAfter.js";
2
+ import { t as UserError } from "./tscAfter.js";
3
3
  // src/common/typescript/typescriptPre7Compiler.ts
4
- /** Uses the `typescript` API for TypeScript 3.9 through 6.x. */
4
+ /** Uses the `typescript` API for TypeScript 4.2 through 6.x. */
5
5
  var TypeScriptPre7Compiler = class {
6
6
  useCaseSensitiveFileNames;
7
7
  constructor() {
@@ -19,10 +19,7 @@ var TypeScriptPre7Compiler = class {
19
19
  };
20
20
  }
21
21
  getOutputPaths(parsedCommandLine, sourceFileNames) {
22
- if (typescriptVersion < 4002e3 && parsedCommandLine.options.rootDir === void 0) throw new UserError("Refusing to clean outDir: TypeScript 3.9 through 4.1 require rootDir to be set.");
23
22
  const emittableFileNames = sourceFileNames.filter((fileName) => !isDeclarationFileName(fileName));
24
- if (typescriptVersion < 4e6 && parsedCommandLine.options.emitDeclarationOnly === true && parsedCommandLine.options.resolveJsonModule === true && emittableFileNames.some((fileName) => fileName.endsWith(".json"))) throw new UserError("Refusing to clean outDir: TypeScript 3.9 cannot safely determine outputs for emitDeclarationOnly with resolveJsonModule.");
25
- if (typescriptVersion < 4e6 && parsedCommandLine.options.allowJs === true && parsedCommandLine.options.jsx === ts.JsxEmit.Preserve && parsedCommandLine.options.declaration === true && emittableFileNames.some((fileName) => fileName.endsWith(".jsx"))) throw new UserError("Refusing to clean outDir: TypeScript 3.9 cannot safely determine outputs for allowJs JSX preserve with declaration.");
26
23
  const outputCommandLine = {
27
24
  ...parsedCommandLine,
28
25
  fileNames: emittableFileNames
package/package.json CHANGED
@@ -1,25 +1,32 @@
1
1
  {
2
2
  "name": "tsc-after",
3
- "version": "0.5.0",
4
- "description": "Remove stale build output that tsc leaves behind when you delete or rename source files. Tsconfig-aware: just run tsc && tsc-after. 🧹",
3
+ "version": "1.0.1",
4
+ "description": "Remove the stale files tsc leaves in outDir. A safe, incremental-friendly replacement for rm -rf dist && tsc, with zero dependencies. 🧹",
5
5
  "keywords": [
6
- "build",
7
6
  "clean",
8
- "dist",
7
+ "cleanup",
8
+ "cli",
9
+ "incremental",
9
10
  "orphan",
10
11
  "outDir",
12
+ "rimraf",
13
+ "rm-rf",
11
14
  "stale",
12
15
  "tsc",
13
- "typescript",
14
- "watch"
16
+ "tsconfig",
17
+ "typescript"
15
18
  ],
19
+ "homepage": "https://github.com/michal-kocarek/tsc-after#readme",
20
+ "bugs": "https://github.com/michal-kocarek/tsc-after/issues",
16
21
  "repository": {
17
22
  "type": "git",
18
23
  "url": "git+https://github.com/michal-kocarek/tsc-after.git"
19
24
  },
25
+ "funding": "https://github.com/sponsors/michal-kocarek",
20
26
  "license": "MIT",
21
27
  "author": {
22
- "name": "michal-kocarek"
28
+ "name": "Michal Kočárek",
29
+ "url": "https://github.com/michal-kocarek"
23
30
  },
24
31
  "sideEffects": false,
25
32
  "type": "module",
@@ -100,7 +107,7 @@
100
107
  "vitest": "5.1.1"
101
108
  },
102
109
  "peerDependencies": {
103
- "typescript": ">=3.9.10 <7 || >=7.1.0-beta <8"
110
+ "typescript": ">=4.2.4 <7 || >=7.1.0-beta <8"
104
111
  },
105
112
  "packageManager": "pnpm@12.21.0",
106
113
  "engines": {