@dotcom-tool-kit/typescript 1.0.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.
package/.toolkitrc.yml ADDED
@@ -0,0 +1,4 @@
1
+ hooks:
2
+ 'build:local': TypescriptBuild
3
+ 'run:local': TypeScriptWatch
4
+ 'test:local': TypescriptTest
package/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { TypeScriptWatch } from './tasks/typescript';
2
+ export declare const tasks: (typeof TypeScriptWatch)[];
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,eAAe,EAAkB,MAAM,oBAAoB,CAAA;AAErF,eAAO,MAAM,KAAK,4BAAqD,CAAA"}
package/lib/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tasks = void 0;
4
+ const typescript_1 = require("./tasks/typescript");
5
+ exports.tasks = [typescript_1.TypeScriptBuild, typescript_1.TypeScriptWatch, typescript_1.TypeScriptTest];
@@ -0,0 +1,20 @@
1
+ import { Task } from '@dotcom-tool-kit/types';
2
+ import type { TypeScriptSchema } from '@dotcom-tool-kit/types/lib/schema/typescript';
3
+ declare abstract class TypeScriptTask extends Task<typeof TypeScriptSchema> {
4
+ abstract taskArgs: string[];
5
+ run(): Promise<void>;
6
+ }
7
+ export declare class TypeScriptBuild extends TypeScriptTask {
8
+ static description: string;
9
+ taskArgs: never[];
10
+ }
11
+ export declare class TypeScriptWatch extends TypeScriptTask {
12
+ static description: string;
13
+ taskArgs: string[];
14
+ }
15
+ export declare class TypeScriptTest extends TypeScriptTask {
16
+ static description: string;
17
+ taskArgs: string[];
18
+ }
19
+ export {};
20
+ //# sourceMappingURL=typescript.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typescript.d.ts","sourceRoot":"","sources":["../../src/tasks/typescript.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAA;AAC7C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8CAA8C,CAAA;AAKpF,uBAAe,cAAe,SAAQ,IAAI,CAAC,OAAO,gBAAgB,CAAC;IACjE,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;IAErB,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAqB3B;AAED,qBAAa,eAAgB,SAAQ,cAAc;IACjD,MAAM,CAAC,WAAW,SAAqC;IAEvD,QAAQ,UAAK;CACd;AAED,qBAAa,eAAgB,SAAQ,cAAc;IACjD,MAAM,CAAC,WAAW,SAAiD;IAEnE,QAAQ,WAAc;CACvB;AAED,qBAAa,cAAe,SAAQ,cAAc;IAChD,MAAM,CAAC,WAAW,SAA+B;IAEjD,QAAQ,WAAe;CACxB"}
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TypeScriptTest = exports.TypeScriptWatch = exports.TypeScriptBuild = void 0;
4
+ const logger_1 = require("@dotcom-tool-kit/logger");
5
+ const types_1 = require("@dotcom-tool-kit/types");
6
+ const child_process_1 = require("child_process");
7
+ const tscPath = require.resolve('typescript/bin/tsc');
8
+ class TypeScriptTask extends types_1.Task {
9
+ async run() {
10
+ // TODO: add monorepo support with --build option
11
+ const args = [...this.taskArgs];
12
+ if (this.options.configPath) {
13
+ args.unshift('--project', this.options.configPath);
14
+ }
15
+ if (this.options.extraArgs) {
16
+ args.push(...this.options.extraArgs);
17
+ }
18
+ const child = (0, child_process_1.fork)(tscPath, args, { silent: true });
19
+ (0, logger_1.hookFork)(this.logger, 'typescript', child);
20
+ const exitPromise = (0, logger_1.waitOnExit)('typescript', child);
21
+ // don't wait for tsc to exit if it's set to watch for file changes
22
+ if (!args.includes('--watch')) {
23
+ await exitPromise;
24
+ }
25
+ // tsc is quite quiet by default so let the user know it actually ran
26
+ this.logger.info('code compiled successfully');
27
+ }
28
+ }
29
+ class TypeScriptBuild extends TypeScriptTask {
30
+ constructor() {
31
+ super(...arguments);
32
+ this.taskArgs = [];
33
+ }
34
+ }
35
+ exports.TypeScriptBuild = TypeScriptBuild;
36
+ TypeScriptBuild.description = 'compile TypeScript to JavaScript';
37
+ class TypeScriptWatch extends TypeScriptTask {
38
+ constructor() {
39
+ super(...arguments);
40
+ this.taskArgs = ['--watch'];
41
+ }
42
+ }
43
+ exports.TypeScriptWatch = TypeScriptWatch;
44
+ TypeScriptWatch.description = 'rebuild TypeScript project every file change';
45
+ class TypeScriptTest extends TypeScriptTask {
46
+ constructor() {
47
+ super(...arguments);
48
+ this.taskArgs = ['--noEmit'];
49
+ }
50
+ }
51
+ exports.TypeScriptTest = TypeScriptTest;
52
+ TypeScriptTest.description = 'type check TypeScript code';
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@dotcom-tool-kit/typescript",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "lib",
6
+ "scripts": {
7
+ "test": "cd ../../ ; npx jest --silent --projects plugins/typescript"
8
+ },
9
+ "keywords": [],
10
+ "author": "FT.com Platforms Team <platforms-team.customer-products@ft.com>",
11
+ "license": "ISC",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/financial-times/dotcom-tool-kit.git",
15
+ "directory": "plugins/typescript"
16
+ },
17
+ "bugs": "https://github.com/financial-times/dotcom-tool-kit/issues",
18
+ "homepage": "https://github.com/financial-times/dotcom-tool-kit/tree/main/plugins/typescript",
19
+ "files": [
20
+ "/lib",
21
+ ".toolkitrc.yml"
22
+ ],
23
+ "peerDependencies": {
24
+ "dotcom-tool-kit": "2.x",
25
+ "typescript": "3.x || 4.x"
26
+ },
27
+ "dependencies": {
28
+ "@dotcom-tool-kit/logger": "^2.1.2",
29
+ "@dotcom-tool-kit/types": "^2.8.0"
30
+ },
31
+ "devDependencies": {
32
+ "@jest/globals": "^29.3.1",
33
+ "typescript": "^4.9.4",
34
+ "winston": "^3.8.2"
35
+ }
36
+ }
package/readme.md ADDED
@@ -0,0 +1,33 @@
1
+ # @dotcom-tool-kit/typescript
2
+
3
+ Tool Kit plugin to build [TypeScript](https://www.typescriptlang.org) code
4
+
5
+ ## Installation & Usage
6
+
7
+ With Tool Kit [already set up](https://github.com/financial-times/dotcom-tool-kit#installing-and-using-tool-kit), install this plugin as a dev dependency:
8
+
9
+ ```sh
10
+ npm install --save-dev @dotcom-tool-kit/typescript
11
+ ```
12
+
13
+ And add it to your repo's `.toolkitrc.yml`:
14
+
15
+ ```yml
16
+ plugins:
17
+ - '@dotcom-tool-kit/typescript'
18
+ ```
19
+
20
+ ## Options
21
+
22
+ | Key | Description | Default value |
23
+ |-|-|-|
24
+ | `configPath` | Path to the [TypeScript config file](https://www.typescriptlang.org/tsconfig) | use TypeScript's own [tsconfig.json resolution](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#using-tsconfigjson-or-jsconfigjson) |
25
+ | `extraArgs` | Extra [arguments](https://www.typescriptlang.org/docs/handbook/compiler-options.html) to pass to the tsc CLI that can't be set in `tsconfig.json` | `[]`
26
+
27
+ ## Tasks
28
+
29
+ | Task | Description | Preconfigured hook |
30
+ |-|-|-|
31
+ | `TypeScriptBuild` | runs `tsc` to compile TypeScript to JavaScript | `build:local` |
32
+ | `TypeScriptWatch` | rebuild project on every project file change | `run:local` |
33
+ | `TypeScriptTest` | type check TypeScript code without emitting code | `test:local` |