@plugjs/typescript 0.6.117 → 0.7.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.
Files changed (66) hide show
  1. package/dist/compiler.d.ts +1 -0
  2. package/dist/compiler.d.ts.map +1 -0
  3. package/dist/compiler.js +61 -0
  4. package/dist/compiler.js.map +1 -0
  5. package/dist/index.d.ts +34 -35
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +9 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/options.d.ts +1 -0
  10. package/dist/options.d.ts.map +1 -0
  11. package/dist/options.js +39 -0
  12. package/dist/options.js.map +1 -0
  13. package/dist/report.d.ts +1 -0
  14. package/dist/report.d.ts.map +1 -0
  15. package/dist/report.js +84 -0
  16. package/dist/report.js.map +1 -0
  17. package/dist/tscbuild.d.ts +32 -0
  18. package/dist/tscbuild.d.ts.map +1 -0
  19. package/dist/tscbuild.js +79 -0
  20. package/dist/tscbuild.js.map +1 -0
  21. package/dist/tsccompiler.d.ts +39 -0
  22. package/dist/tsccompiler.d.ts.map +1 -0
  23. package/dist/tsccompiler.js +75 -0
  24. package/dist/tsccompiler.js.map +1 -0
  25. package/dist/typescript.d.ts +1 -0
  26. package/dist/typescript.d.ts.map +1 -0
  27. package/dist/typescript.js +135 -0
  28. package/dist/typescript.js.map +1 -0
  29. package/dist/writefile.d.ts +1 -0
  30. package/dist/writefile.d.ts.map +1 -0
  31. package/dist/writefile.js +21 -0
  32. package/dist/writefile.js.map +1 -0
  33. package/package.json +12 -22
  34. package/src/index.ts +42 -52
  35. package/src/report.ts +2 -7
  36. package/src/tscbuild.ts +56 -4
  37. package/src/tsccompiler.ts +130 -0
  38. package/src/typescript.ts +5 -6
  39. package/dist/compiler.cjs +0 -100
  40. package/dist/compiler.cjs.map +0 -6
  41. package/dist/compiler.mjs +0 -65
  42. package/dist/compiler.mjs.map +0 -6
  43. package/dist/index.cjs +0 -40
  44. package/dist/index.cjs.map +0 -6
  45. package/dist/index.mjs +0 -15
  46. package/dist/index.mjs.map +0 -6
  47. package/dist/options.cjs +0 -75
  48. package/dist/options.cjs.map +0 -6
  49. package/dist/options.mjs +0 -40
  50. package/dist/options.mjs.map +0 -6
  51. package/dist/report.cjs +0 -117
  52. package/dist/report.cjs.map +0 -6
  53. package/dist/report.mjs +0 -82
  54. package/dist/report.mjs.map +0 -6
  55. package/dist/tscbuild.cjs +0 -122
  56. package/dist/tscbuild.cjs.map +0 -6
  57. package/dist/tscbuild.mjs +0 -87
  58. package/dist/tscbuild.mjs.map +0 -6
  59. package/dist/typescript.cjs +0 -136
  60. package/dist/typescript.cjs.map +0 -6
  61. package/dist/typescript.mjs +0 -101
  62. package/dist/typescript.mjs.map +0 -6
  63. package/dist/writefile.cjs +0 -56
  64. package/dist/writefile.cjs.map +0 -6
  65. package/dist/writefile.mjs +0 -21
  66. package/dist/writefile.mjs.map +0 -6
@@ -0,0 +1,135 @@
1
+ import { assert } from '@plugjs/plug/asserts';
2
+ import { Files } from '@plugjs/plug/files';
3
+ import { $p } from '@plugjs/plug/logging';
4
+ import { commonPath, getAbsoluteParent, resolveAbsolutePath, resolveFile } from '@plugjs/plug/paths';
5
+ import { parseOptions, walk } from '@plugjs/plug/utils';
6
+ import ts from 'typescript';
7
+ import { TypeScriptHost } from "./compiler.js";
8
+ import { getCompilerOptions } from "./options.js";
9
+ import { updateReport } from "./report.js";
10
+ import { buildWriteFile } from "./writefile.js";
11
+ /* ========================================================================== *
12
+ * WORKER PLUG *
13
+ * ========================================================================== */
14
+ function defaultRootDir(paths) {
15
+ const [firstPath, ...restPaths] = paths.filter((path) => {
16
+ return !path.match(/\.d\.[mc]?ts$/i);
17
+ });
18
+ assert(firstPath, 'No non-declaration files found to compile');
19
+ if (restPaths.length)
20
+ return commonPath(firstPath, ...restPaths);
21
+ return getAbsoluteParent(firstPath);
22
+ }
23
+ export class Tsc {
24
+ _tsconfig;
25
+ _options;
26
+ constructor(...args) {
27
+ const { params: [tsconfig], options } = parseOptions(args, {});
28
+ this._tsconfig = tsconfig;
29
+ this._options = options;
30
+ }
31
+ async pipe(files, context) {
32
+ const paths = [...files.absolutePaths()];
33
+ /* Start preparing the report that will be used throughout */
34
+ const report = context.log.report('TypeScript Report');
35
+ /* Clone our options and add extra types to our sources */
36
+ const { extraTypesDir, ...__overrides } = { ...this._options };
37
+ if (extraTypesDir) {
38
+ const directory = context.resolve(extraTypesDir);
39
+ for await (const file of walk(directory, ['**/*.d.ts'])) {
40
+ const path = resolveAbsolutePath(directory, file);
41
+ context.log.debug(`Including extra type file "${$p(path)}"`);
42
+ paths.push(path);
43
+ }
44
+ }
45
+ /*
46
+ * The "tsconfig" file is either specified, or (if existing) first checked
47
+ * alongside the sources, otherwise checked in the current directory.
48
+ */
49
+ const sourcesConfig = resolveFile(files.directory, 'tsconfig.json');
50
+ const tsconfig = this._tsconfig ? context.resolve(this._tsconfig) :
51
+ sourcesConfig || resolveFile(context.resolve('tsconfig.json'));
52
+ /* Root directory must always exist */
53
+ // let rootDir: AbsolutePath
54
+ if (__overrides.rootDir) {
55
+ __overrides.rootDir = context.resolve(__overrides.rootDir);
56
+ }
57
+ /* Output directory _also_ must always exist */
58
+ // let outDir: AbsolutePath
59
+ if (__overrides.outDir) {
60
+ __overrides.outDir = context.resolve(__overrides.outDir);
61
+ }
62
+ /* All other root paths */
63
+ if (__overrides.rootDirs) {
64
+ __overrides.rootDirs = __overrides.rootDirs.map((dir) => context.resolve(dir));
65
+ }
66
+ /* The baseURL is resolved, as well */
67
+ if (__overrides.baseUrl)
68
+ __overrides.baseUrl = context.resolve(__overrides.baseUrl);
69
+ /* The baseURL is resolved, as well */
70
+ if (__overrides.outFile)
71
+ __overrides.outFile = context.resolve(__overrides.outFile);
72
+ /* We can now get our compiler options, and check any and all overrides */
73
+ const { errors, options, projectReferences } = await getCompilerOptions(tsconfig, // resolved tsconfig.json from constructor, might be undefined
74
+ __overrides, paths); // overrides from constructor, might be an empty object
75
+ /* Update report and fail on errors */
76
+ updateReport(report, errors, context.resolve('.'));
77
+ if (report.errors)
78
+ report.done(true);
79
+ /* Prep for compilation */
80
+ for (const path of paths)
81
+ context.log.debug(`Compiling "${$p(path)}"`);
82
+ context.log.info('Compiling', paths.length, 'files');
83
+ /* If we have an extra types directory, add all the .d.ts files in there */
84
+ if (extraTypesDir) {
85
+ const directory = context.resolve(extraTypesDir);
86
+ for await (const file of walk(directory, ['**/*.d.ts'])) {
87
+ const path = resolveAbsolutePath(directory, file);
88
+ context.log.debug(`Including extra type file "${$p(path)}"`);
89
+ paths.push(path);
90
+ }
91
+ }
92
+ /* Figure out the root directory, either from the options, or default */
93
+ const rootDir = options.rootDir ?
94
+ context.resolve(options.rootDir) :
95
+ defaultRootDir(paths);
96
+ if (!(options.rootDir || options.rootDirs))
97
+ options.rootDir = rootDir;
98
+ /* Figure out the output directory, either from the options or same as root */
99
+ const outDir = options.outDir ? context.resolve(options.outDir) : rootDir;
100
+ if (!(options.outDir || options.outFile))
101
+ options.outDir = outDir;
102
+ /* Log out what we'll be our final compilation options */
103
+ context.log.info('Compliation options', options);
104
+ if (projectReferences?.length)
105
+ context.log.info('Project references', projectReferences);
106
+ /* Typescript host, create program and compile */
107
+ const host = new TypeScriptHost(rootDir);
108
+ const program = ts.createProgram({
109
+ configFileParsingDiagnostics: errors,
110
+ rootNames: paths,
111
+ projectReferences,
112
+ options,
113
+ host,
114
+ });
115
+ const diagnostics = ts.getPreEmitDiagnostics(program);
116
+ /* Update report and fail on errors */
117
+ updateReport(report, diagnostics, rootDir);
118
+ if (report.errors)
119
+ report.done(true);
120
+ /* Write out all files asynchronously */
121
+ const builder = Files.builder(outDir);
122
+ const writeFile = buildWriteFile(builder, context);
123
+ const result = program.emit(undefined, writeFile);
124
+ /* Update report and fail on errors */
125
+ updateReport(report, result.diagnostics, rootDir);
126
+ /* coverage ignore if / only on write errors */
127
+ if (report.errors)
128
+ report.done(true);
129
+ /* All done, build our files and return it */
130
+ const outputs = builder.build();
131
+ context.log.info('TSC produced', outputs.length, 'files into', $p(outputs.directory));
132
+ return outputs;
133
+ }
134
+ }
135
+ //# sourceMappingURL=typescript.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typescript.js","sourceRoot":"","sources":["../src/typescript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC1C,OAAO,EAAE,EAAE,EAAE,MAAM,sBAAsB,CAAA;AACzC,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AACpG,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,EAAE,MAAM,YAAY,CAAA;AAE3B,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAM/C;;gFAEgF;AAEhF,SAAS,cAAc,CAAC,KAAqB;IAC3C,MAAM,CAAE,SAAS,EAAE,GAAG,SAAS,CAAE,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;QACxD,OAAO,CAAE,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAA;IACvC,CAAC,CAAC,CAAA;IAEF,MAAM,CAAC,SAAS,EAAE,2CAA2C,CAAC,CAAA;IAC9D,IAAI,SAAS,CAAC,MAAM;QAAE,OAAO,UAAU,CAAC,SAAS,EAAE,GAAG,SAAS,CAAC,CAAA;IAChE,OAAO,iBAAiB,CAAC,SAAS,CAAC,CAAA;AACrC,CAAC;AAED,MAAM,OAAO,GAAG;IACG,SAAS,CAAS;IAClB,QAAQ,CAAyB;IAElD,YAAY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AAE,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAA;QACrF,OAAO,OAAO,CAAA;IAChB,CAAC;CACF"}
@@ -3,3 +3,4 @@ import type { FilesBuilder } from '@plugjs/plug/files';
3
3
  import type { Context } from '@plugjs/plug/pipe';
4
4
  /** Write a file (using `ts.sys.writeFile`) and add it to the builder */
5
5
  export declare function buildWriteFile(builder: FilesBuilder, context: Context): ts.WriteFileCallback;
6
+ //# sourceMappingURL=writefile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writefile.d.ts","sourceRoot":"","sources":["../src/writefile.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,YAAY,CAAA;AAE3B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAEhD,wEAAwE;AACxE,wBAAgB,cAAc,CAC1B,OAAO,EAAE,YAAY,EACrB,OAAO,EAAE,OAAO,GACjB,EAAE,CAAC,iBAAiB,CAkBtB"}
@@ -0,0 +1,21 @@
1
+ import { $p } from '@plugjs/plug';
2
+ import { resolveAbsolutePath } from '@plugjs/plug/paths';
3
+ import ts from 'typescript';
4
+ /** Write a file (using `ts.sys.writeFile`) and add it to the builder */
5
+ export function buildWriteFile(builder, context) {
6
+ return function writeFile(fileName, code, writeBOM, onError) {
7
+ const outFile = resolveAbsolutePath(builder.directory, fileName);
8
+ /* coverage ignore catch */
9
+ try {
10
+ ts.sys.writeFile(outFile, code, writeBOM);
11
+ builder.add(outFile);
12
+ }
13
+ catch (error) {
14
+ context.log.error('Error writing to', $p(outFile), error);
15
+ if (onError && error.message)
16
+ onError(error.message);
17
+ throw error;
18
+ }
19
+ };
20
+ }
21
+ //# sourceMappingURL=writefile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writefile.js","sourceRoot":"","sources":["../src/writefile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,cAAc,CAAA;AACjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,EAAE,MAAM,YAAY,CAAA;AAK3B,wEAAwE;AACxE,MAAM,UAAU,cAAc,CAC1B,OAAqB,EACrB,OAAgB;IAElB,OAAO,SAAS,SAAS,CACrB,QAAgB,EAChB,IAAY,EACZ,QAAiB,EACjB,OAAmC;QAErC,MAAM,OAAO,GAAG,mBAAmB,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAA;QAChE,2BAA2B;QAC3B,IAAI,CAAC;YACH,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAA;YACzC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;QACtB,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,kBAAkB,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,CAAA;YACzD,IAAI,OAAO,IAAI,KAAK,CAAC,OAAO;gBAAE,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;YACpD,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC,CAAA;AACH,CAAC"}
package/package.json CHANGED
@@ -1,39 +1,29 @@
1
1
  {
2
2
  "name": "@plugjs/typescript",
3
- "version": "0.6.117",
3
+ "version": "0.7.0",
4
4
  "type": "module",
5
- "main": "./dist/index.cjs",
6
- "module": "./dist/index.mjs",
5
+ "main": "./dist/index.js",
7
6
  "types": "./dist/index.d.ts",
8
7
  "exports": {
9
8
  ".": {
10
- "require": {
11
- "types": "./dist/index.d.ts",
12
- "default": "./dist/index.cjs"
13
- },
14
- "import": {
15
- "types": "./dist/index.d.ts",
16
- "default": "./dist/index.mjs"
17
- }
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
18
11
  },
19
12
  "./typescript": {
20
- "require": {
21
- "types": "./dist/typescript.d.ts",
22
- "default": "./dist/typescript.cjs"
23
- },
24
- "import": {
25
- "types": "./dist/typescript.d.ts",
26
- "default": "./dist/typescript.mjs"
27
- }
13
+ "types": "./dist/typescript.d.ts",
14
+ "default": "./dist/typescript.js"
28
15
  }
29
16
  },
30
17
  "author": "Juit Developers <developers@juit.com>",
31
18
  "license": "Apache-2.0",
19
+ "engines": {
20
+ "node": ">=22.16.0"
21
+ },
32
22
  "dependencies": {
33
- "typescript": "<6"
23
+ "typescript": "<7"
34
24
  },
35
25
  "peerDependencies": {
36
- "@plugjs/plug": "0.6.117"
26
+ "@plugjs/plug": "0.7.0"
37
27
  },
38
28
  "files": [
39
29
  "*.md",
@@ -42,7 +32,7 @@
42
32
  ],
43
33
  "repository": {
44
34
  "type": "git",
45
- "url": "git+ssh://git@github.com/plugjs/plug.git"
35
+ "url": "git+https://github.com/plugjs/plug.git"
46
36
  },
47
37
  "keywords": [
48
38
  "build",
package/src/index.ts CHANGED
@@ -1,17 +1,19 @@
1
- import { find } from '@plugjs/plug'
2
1
  import { installForking } from '@plugjs/plug/fork'
3
2
  import { requireResolve } from '@plugjs/plug/paths'
4
3
 
5
- import type { Pipe } from '@plugjs/plug'
6
4
  import type { BuildOptions, CompilerOptions } from 'typescript'
7
5
 
8
6
  /** Remove the mapped `[option: string]: ...` from `CompilerOptions`. */
9
- type KnownCompilerOptions = {
10
- [ k in keyof CompilerOptions as string extends k ? never : k ]: CompilerOptions[k]
7
+ type RemoveIndexSignature<T> = {
8
+ [ k in keyof T as
9
+ string extends k ? never :
10
+ number extends k ? never :
11
+ symbol extends k ? never :
12
+ k ]: T[k]
11
13
  }
12
14
 
13
15
  /** TypeScript Compiler options with some additional properties */
14
- export interface ExtendedCompilerOptions extends KnownCompilerOptions {
16
+ export interface ExtendedCompilerOptions extends RemoveIndexSignature<CompilerOptions> {
15
17
  /**
16
18
  * An additional directory containing a set of `.d.ts` files which will
17
19
  * be part of the compilation input, but not of the output.
@@ -23,6 +25,15 @@ export interface ExtendedCompilerOptions extends KnownCompilerOptions {
23
25
  extraTypesDir?: string | undefined
24
26
  }
25
27
 
28
+ export interface TscBuildOptions extends RemoveIndexSignature<BuildOptions> {}
29
+ export interface TscCompilerOptions extends RemoveIndexSignature<CompilerOptions> {}
30
+
31
+ /* Exports for "tscBuild" and "tsc" */
32
+ export { tscBuild } from './tscbuild.ts'
33
+ export type { ExtendedTscBuildOptions } from './tscbuild.ts'
34
+ export { tsc } from './tsccompiler.ts'
35
+ export type { ExtendedTscCompilerOptions } from './tsccompiler.ts'
36
+
26
37
  declare module '@plugjs/plug' {
27
38
  export interface Pipe {
28
39
  /**
@@ -63,6 +74,8 @@ declare module '@plugjs/plug' {
63
74
  /**
64
75
  * Run the {@link https://www.typescriptlang.org/ TypeScript Builder}
65
76
  * over the specified project `tsconfig.json` files.
77
+ *
78
+ * This is equivalent to running `tsc --build` from the command line.
66
79
  */
67
80
  tscBuild(): Pipe
68
81
 
@@ -70,59 +83,36 @@ declare module '@plugjs/plug' {
70
83
  * Run the {@link https://www.typescriptlang.org/ TypeScript Builder}
71
84
  * over the specified project `tsconfig.json` files.
72
85
  *
86
+ * This is equivalent to running `tsc --build ...` from the command line.
87
+ *
73
88
  * With regards to `options`, the defaults are:
74
89
  * - `verbose: true`
75
90
  * - `force: true`
76
91
  *
77
- * @param options {@link BuildOptions} to use for the build.
92
+ * @param options {@link TscBuildOptions} to use for the build.
78
93
  */
79
- tscBuild(options: BuildOptions): Pipe
80
- }
81
- }
94
+ tscBuild(options: TscBuildOptions): Pipe
82
95
 
83
- installForking('tsc', requireResolve(__fileurl, './typescript'), 'Tsc')
84
- installForking('tscBuild', requireResolve(__fileurl, './tscbuild'), 'TscBuild')
96
+ /**
97
+ * Run the {@link https://www.typescriptlang.org/ TypeScript Compiler}
98
+ * over the specified project `tsconfig.json` files.
99
+ *
100
+ * This is equivalent to running `tsc --project ...` from the command line.
101
+ */
102
+ tscCompiler(): Pipe
85
103
 
86
- export interface TscBuildOptions extends BuildOptions {
87
- /** The directory where to look for the `tsconfig.json` files. */
88
- directory?: string
104
+ /**
105
+ * Run the {@link https://www.typescriptlang.org/ TypeScript Compiler}
106
+ * over the specified project `tsconfig.json` files.
107
+ *
108
+ * This is equivalent to running `tsc --project ...` from the command line.
109
+ *
110
+ * @param options {@link TscCompilerOptions} to use for the build.
111
+ */
112
+ tscCompiler(options: TscCompilerOptions): Pipe
113
+ }
89
114
  }
90
115
 
91
- /**
92
- * Run `tsc --build` using `tsconfig.json` from the current directory.
93
- */
94
- export function tscBuild(): Pipe
95
- /**
96
- * Run `tsc --build` using the specified `tsconfig.json` file.
97
- */
98
- export function tscBuild(tsconfig: string): Pipe
99
- /**
100
- * Run `tsc --build` using the specified options.
101
- *
102
- * The `directory` option specifies where to look for the `tsconfig.json` files,
103
- * and defaults to the current directory, `verbose` and `force` default to
104
- * `true`.
105
- */
106
- export function tscBuild(options: TscBuildOptions): Pipe
107
- /**
108
- * Run `tsc --build` using the specified `tsconfig.json` and options.
109
- *
110
- * The `directory` option specifies where to look for the `tsconfig.json` files,
111
- * and defaults to the current directory, `verbose` and `force` default to
112
- * `true`.
113
- */
114
- export function tscBuild(tsconfig: string, options?: TscBuildOptions): Pipe
115
-
116
- // Implementation overload
117
- export function tscBuild(
118
- tsconfigOrOptions?: string | TscBuildOptions,
119
- maybeOptions?: TscBuildOptions,
120
- ): Pipe {
121
- const [ tsconfig, tscBuildOptions ] =
122
- typeof tsconfigOrOptions === 'string'
123
- ? [ tsconfigOrOptions, maybeOptions ]
124
- : [ 'tsconfig.json', tsconfigOrOptions ]
125
-
126
- const { directory, ...buildOptions } = tscBuildOptions || {}
127
- return find(tsconfig, { directory }).tscBuild(buildOptions)
128
- }
116
+ installForking('tsc', requireResolve(import.meta.filename, './typescript'), 'Tsc')
117
+ installForking('tscBuild', requireResolve(import.meta.filename, './tscbuild'), 'TscBuild')
118
+ installForking('tscCompiler', requireResolve(import.meta.filename, './tsccompiler'), 'TscCompiler')
package/src/report.ts CHANGED
@@ -46,7 +46,6 @@ function convertDiagnostics(
46
46
  // Simple variables
47
47
  const tags = `TS${diagnostic.code}`
48
48
 
49
-
50
49
  if (diagnostic.file) {
51
50
  const { file: sourceFile, start, length } = diagnostic
52
51
  const file = resolveAbsolutePath(directory, sourceFile.fileName)
@@ -89,14 +88,10 @@ export function updateReport(
89
88
  }
90
89
 
91
90
  for (const record of records) {
92
- if (record.file) {
91
+ if ((record.file) || (record.level != NOTICE)) {
93
92
  report.add(record)
94
93
  } else {
95
- switch (record.level) {
96
- case ERROR: logger.error(record.message); break
97
- case WARN: logger.warn(record.message); break
98
- case NOTICE: logger.info(record.message); break
99
- }
94
+ logger.info(record.message)
100
95
  }
101
96
  }
102
97
  }
package/src/tscbuild.ts CHANGED
@@ -1,11 +1,13 @@
1
- import { $p, fail } from '@plugjs/plug'
1
+ import { $p, assert, fail, find } from '@plugjs/plug'
2
2
  import { Files } from '@plugjs/plug/files'
3
3
  import ts from 'typescript'
4
4
 
5
- import { updateReport } from './report'
6
- import { buildWriteFile } from './writefile'
5
+ import { updateReport } from './report.ts'
6
+ import { buildWriteFile } from './writefile.ts'
7
7
 
8
+ import type { Pipe } from '@plugjs/plug'
8
9
  import type { Context, PipeParameters, Plug } from '@plugjs/plug/pipe'
10
+ import type { TscBuildOptions } from './index.ts'
9
11
 
10
12
  export class TscBuild implements Plug<Files> {
11
13
  private readonly _options: ts.BuildOptions
@@ -32,7 +34,6 @@ export class TscBuild implements Plug<Files> {
32
34
  undefined, // createProgram
33
35
  reporter, // reportDiagnostic
34
36
  reporter, // reportSolutionBuilderStatus
35
- undefined, // reportSolutionBuilderErrorSummary
36
37
  )
37
38
 
38
39
  const solutionBuilder = ts.createSolutionBuilder(
@@ -84,3 +85,54 @@ export class TscBuild implements Plug<Files> {
84
85
  return outputs
85
86
  }
86
87
  }
88
+
89
+ /* ========================================================================== */
90
+
91
+ /** Options available for the TypeScript Builder. */
92
+ export interface ExtendedTscBuildOptions extends TscBuildOptions {
93
+ /** The directory where to look for the `tsconfig.json` files. */
94
+ directory?: string
95
+ }
96
+
97
+ /**
98
+ * Run `tsc --build` using `tsconfig.json` from the current directory.
99
+ */
100
+ export function tscBuild(): Pipe
101
+ /**
102
+ * Run `tsc --build` using the specified `tsconfig.json` file.
103
+ */
104
+ export function tscBuild(tsconfig: string): Pipe
105
+ /**
106
+ * Run `tsc --build` using the specified options.
107
+ *
108
+ * The `directory` option specifies where to look for the `tsconfig.json` files,
109
+ * and defaults to the current directory, `verbose` and `force` default to
110
+ * `true`.
111
+ */
112
+ export function tscBuild(options: ExtendedTscBuildOptions): Pipe
113
+ /**
114
+ * Run `tsc --build` using the specified `tsconfig.json` and options.
115
+ *
116
+ * The `directory` option specifies where to look for the `tsconfig.json` files,
117
+ * and defaults to the current directory, `verbose` and `force` default to
118
+ * `true`.
119
+ */
120
+ export function tscBuild(tsconfig: string, options?: ExtendedTscBuildOptions): Pipe
121
+ // Implementation overload
122
+ export function tscBuild(
123
+ tsconfigOrOptions?: string | ExtendedTscBuildOptions,
124
+ maybeOptions?: ExtendedTscBuildOptions,
125
+ ): Pipe {
126
+ const [ tsconfig, tscBuildOptions ] =
127
+ typeof tsconfigOrOptions === 'string'
128
+ ? [ tsconfigOrOptions, maybeOptions ]
129
+ : [ 'tsconfig.json', tsconfigOrOptions ]
130
+
131
+ const { directory, ...buildOptions } = tscBuildOptions || {}
132
+ return find(tsconfig, { directory })
133
+ .plug((files) => {
134
+ assert(files.length > 0, `No match for "${tsconfig}" in directory "${files.directory}"`)
135
+ return files
136
+ })
137
+ .plug(new TscBuild(buildOptions))
138
+ }
@@ -0,0 +1,130 @@
1
+ import { $p, assert, find } from '@plugjs/plug'
2
+ import { Files } from '@plugjs/plug/files'
3
+ import { getAbsoluteParent } from '@plugjs/plug/paths'
4
+ import ts from 'typescript'
5
+
6
+ import { updateReport } from './report.ts'
7
+ import { buildWriteFile } from './writefile.ts'
8
+
9
+ import type { Pipe } from '@plugjs/plug'
10
+ import type { Context, PipeParameters, Plug } from '@plugjs/plug/pipe'
11
+ import type { TscCompilerOptions } from './index.ts'
12
+
13
+ export class TscCompiler implements Plug<Files> {
14
+ private readonly _options: ts.CompilerOptions
15
+
16
+ constructor(...args: PipeParameters<'tscCompiler'>) {
17
+ this._options = {
18
+ verbose: true,
19
+ force: true,
20
+ ...(args[0] || {}),
21
+ }
22
+ }
23
+
24
+ async pipe(files: Files, context: Context): Promise<Files> {
25
+ const report = context.log.report('TypeScript Compiler Report')
26
+ const builder = Files.builder(files.directory)
27
+ const writeFile = buildWriteFile(builder, context)
28
+
29
+ for (const absoluteConfigPath of files.absolutePaths()) {
30
+ context.log.notice('Compiling TypeScript project', $p(absoluteConfigPath))
31
+ const configDir = getAbsoluteParent(absoluteConfigPath)
32
+
33
+ /* Read the config file */
34
+ const configFile = ts.readConfigFile(
35
+ absoluteConfigPath,
36
+ ts.sys.readFile,
37
+ )
38
+
39
+ if (configFile.error) {
40
+ updateReport(report, [ configFile.error ], configDir)
41
+ if (report.errors) report.done(true)
42
+ }
43
+
44
+ /* Parse the config file */
45
+ const parsedConfig = ts.parseJsonConfigFileContent(
46
+ configFile.config, // the JSON
47
+ ts.sys, // the system
48
+ configDir, // the base directory to resolve relative paths
49
+ this._options, // existing options to merge with
50
+ absoluteConfigPath, // the config file name
51
+ )
52
+
53
+ if (parsedConfig.errors.length > 0) {
54
+ updateReport(report, parsedConfig.errors, configDir)
55
+ if (report.errors) report.done(true)
56
+ }
57
+
58
+ /* Create the program */
59
+ const program = ts.createProgram({
60
+ rootNames: parsedConfig.fileNames,
61
+ options: parsedConfig.options,
62
+ projectReferences: parsedConfig.projectReferences,
63
+ configFileParsingDiagnostics: parsedConfig.errors,
64
+ })
65
+
66
+ const diagnostics = ts.getPreEmitDiagnostics(program)
67
+ updateReport(report, diagnostics, configDir)
68
+ if (report.errors) report.done(true)
69
+
70
+ const result = program.emit(undefined, writeFile)
71
+ updateReport(report, result.diagnostics, configDir)
72
+ if (report.errors) report.done(true)
73
+ }
74
+
75
+ const result = builder.build()
76
+ context.log.info('TSC Build produced', result.length, 'files into', $p(result.directory))
77
+ return result
78
+ }
79
+ }
80
+
81
+ /* ========================================================================== */
82
+
83
+ /** Options available for the TypeScript Compiler. */
84
+ export interface ExtendedTscCompilerOptions extends TscCompilerOptions {
85
+ /** The directory where to look for the `tsconfig.json` files. */
86
+ directory?: string
87
+ }
88
+
89
+ /**
90
+ * Run `tsc --project` using `tsconfig.json` from the current directory.
91
+ */
92
+ export function tsc(): Pipe
93
+ /**
94
+ * Run `tsc --project` using the specified `tsconfig.json` file.
95
+ */
96
+ export function tsc(tsconfig: string): Pipe
97
+ /**
98
+ * Run `tsc --project` using the specified options.
99
+ *
100
+ * The `directory` option specifies where to look for the `tsconfig.json` files,
101
+ * and defaults to the current directory, `verbose` and `force` default to
102
+ * `true`.
103
+ */
104
+ export function tsc(options: ExtendedTscCompilerOptions): Pipe
105
+ /**
106
+ * Run `tsc --project` using the specified `tsconfig.json` and options.
107
+ *
108
+ * The `directory` option specifies where to look for the `tsconfig.json` files,
109
+ * and defaults to the current directory, `verbose` and `force` default to
110
+ * `true`.
111
+ */
112
+ export function tsc(tsconfig: string, options?: ExtendedTscCompilerOptions): Pipe
113
+ // Implementation overload
114
+ export function tsc(
115
+ tsconfigOrOptions?: string | ExtendedTscCompilerOptions,
116
+ maybeOptions?: ExtendedTscCompilerOptions,
117
+ ): Pipe {
118
+ const [ tsconfig, tscCompilerOptions ] =
119
+ typeof tsconfigOrOptions === 'string'
120
+ ? [ tsconfigOrOptions, maybeOptions ]
121
+ : [ 'tsconfig.json', tsconfigOrOptions ]
122
+
123
+ const { directory, ...compilerOptions } = tscCompilerOptions || {}
124
+ return find(tsconfig, { directory })
125
+ .plug((files) => {
126
+ assert(files.length > 0, `No match for "${tsconfig}" in directory "${files.directory}"`)
127
+ return files
128
+ })
129
+ .plug(new TscCompiler(compilerOptions))
130
+ }
package/src/typescript.ts CHANGED
@@ -5,15 +5,14 @@ import { commonPath, getAbsoluteParent, resolveAbsolutePath, resolveFile } from
5
5
  import { parseOptions, walk } from '@plugjs/plug/utils'
6
6
  import ts from 'typescript'
7
7
 
8
- import { TypeScriptHost } from './compiler'
9
- import { getCompilerOptions } from './options'
10
- import { updateReport } from './report'
11
- import { buildWriteFile } from './writefile'
8
+ import { TypeScriptHost } from './compiler.ts'
9
+ import { getCompilerOptions } from './options.ts'
10
+ import { updateReport } from './report.ts'
11
+ import { buildWriteFile } from './writefile.ts'
12
12
 
13
13
  import type { AbsolutePath } from '@plugjs/plug/paths'
14
14
  import type { Context, PipeParameters, Plug } from '@plugjs/plug/pipe'
15
- import type { ExtendedCompilerOptions } from './index'
16
-
15
+ import type { ExtendedCompilerOptions } from './index.ts'
17
16
 
18
17
  /* ========================================================================== *
19
18
  * WORKER PLUG *