@langri-sha/projen-typescript-config 0.1.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/CHANGELOG.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@langri-sha/projen-typescript-config",
3
+ "entries": [
4
+ {
5
+ "date": "Tue, 14 May 2024 20:39:52 GMT",
6
+ "version": "0.1.0",
7
+ "tag": "@langri-sha/projen-typescript-config_v0.1.0",
8
+ "comments": {
9
+ "minor": [
10
+ {
11
+ "author": "filip.dupanovic@gmail.com",
12
+ "package": "@langri-sha/projen-typescript-config",
13
+ "commit": "bb5eca0acea87c11cf873197bea7383eef3f8465",
14
+ "comment": "feat(typescript-config): Add support for managing TypeScript config files\""
15
+ }
16
+ ]
17
+ }
18
+ }
19
+ ]
20
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # Change Log - @langri-sha/projen-typescript-config
2
+
3
+ This log was last generated on Tue, 14 May 2024 20:39:52 GMT and should not be manually modified.
4
+
5
+ <!-- Start content -->
6
+
7
+ ## 0.1.0
8
+
9
+ Tue, 14 May 2024 20:39:52 GMT
10
+
11
+ ### Minor changes
12
+
13
+ - feat(typescript-config): Add support for managing TypeScript config files" (filip.dupanovic@gmail.com)
package/lib/index.d.ts ADDED
@@ -0,0 +1,37 @@
1
+ import type { JSONSchemaForTheTypeScriptCompilerSConfigurationFile } from '@schemastore/tsconfig';
2
+ import { Component, Project } from 'projen';
3
+ export interface TypeScriptConfigOptions {
4
+ config?: JSONSchemaForTheTypeScriptCompilerSConfigurationFile & {
5
+ /**
6
+ * Referenced projects. Requires TypeScript version 3.0 or later.
7
+ */
8
+ references?: {
9
+ /**
10
+ * Path to referenced tsconfig or to folder containing tsconfig.
11
+ */
12
+ path: string;
13
+ }[];
14
+ };
15
+ fileName?: string;
16
+ }
17
+ export declare class TypeScriptConfig extends Component {
18
+ #private;
19
+ constructor(project: Project, options: TypeScriptConfigOptions);
20
+ /**
21
+ * Appends to the list of filenames and patterns to exclude in the program.
22
+ */
23
+ addExclude(fileNameOrPattern: string): void;
24
+ /**
25
+ * Appends to the list of filenames and patterns to include in the program.
26
+ */
27
+ addInclude(fileNameOrPattern: string): void;
28
+ /**
29
+ * Appends to the list of filenames to include in the program.
30
+ */
31
+ addFile(fileName: string): void;
32
+ /**
33
+ * Adds a reference project.
34
+ */
35
+ addReference(path: string): void;
36
+ }
37
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oDAAoD,EAAE,MAAM,uBAAuB,CAAA;AACjG,OAAO,EAAE,SAAS,EAAY,OAAO,EAAE,MAAM,QAAQ,CAAA;AAErD,MAAM,WAAW,uBAAuB;IACtC,MAAM,CAAC,EAAE,oDAAoD,GAAG;QAC9D;;WAEG;QACH,UAAU,CAAC,EAAE;YACX;;eAEG;YACH,IAAI,EAAE,MAAM,CAAA;SACb,EAAE,CAAA;KACJ,CAAA;IACD,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,qBAAa,gBAAiB,SAAQ,SAAS;;gBAIjC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,uBAAuB;IAmB9D;;OAEG;IACH,UAAU,CAAC,iBAAiB,EAAE,MAAM;IAIpC;;OAEG;IACH,UAAU,CAAC,iBAAiB,EAAE,MAAM;IAIpC;;OAEG;IACH,OAAO,CAAC,QAAQ,EAAE,MAAM;IAIxB;;OAEG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM;CAK1B"}
package/lib/index.js ADDED
@@ -0,0 +1,60 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _TypeScriptConfig_file, _TypeScriptConfig_options;
13
+ import { Component, JsonFile } from 'projen';
14
+ export class TypeScriptConfig extends Component {
15
+ constructor(project, options) {
16
+ const fileName = options.fileName ?? 'tsconfig.json';
17
+ super(project, fileName);
18
+ _TypeScriptConfig_file.set(this, void 0);
19
+ _TypeScriptConfig_options.set(this, void 0);
20
+ __classPrivateFieldSet(this, _TypeScriptConfig_options, {
21
+ config: options.config ?? {},
22
+ fileName,
23
+ }, "f");
24
+ __classPrivateFieldSet(this, _TypeScriptConfig_file, new JsonFile(this, 'tsconfig.json', {
25
+ allowComments: true,
26
+ obj: {
27
+ $schema: 'http://json.schemastore.org/tsconfig',
28
+ ...__classPrivateFieldGet(this, _TypeScriptConfig_options, "f").config,
29
+ },
30
+ }), "f");
31
+ }
32
+ /**
33
+ * Appends to the list of filenames and patterns to exclude in the program.
34
+ */
35
+ addExclude(fileNameOrPattern) {
36
+ __classPrivateFieldGet(this, _TypeScriptConfig_file, "f").addToArray('exclude', fileNameOrPattern);
37
+ }
38
+ /**
39
+ * Appends to the list of filenames and patterns to include in the program.
40
+ */
41
+ addInclude(fileNameOrPattern) {
42
+ __classPrivateFieldGet(this, _TypeScriptConfig_file, "f").addToArray('include', fileNameOrPattern);
43
+ }
44
+ /**
45
+ * Appends to the list of filenames to include in the program.
46
+ */
47
+ addFile(fileName) {
48
+ __classPrivateFieldGet(this, _TypeScriptConfig_file, "f").addToArray('files', fileName);
49
+ }
50
+ /**
51
+ * Adds a reference project.
52
+ */
53
+ addReference(path) {
54
+ __classPrivateFieldGet(this, _TypeScriptConfig_file, "f").addToArray('references', {
55
+ path,
56
+ });
57
+ }
58
+ }
59
+ _TypeScriptConfig_file = new WeakMap(), _TypeScriptConfig_options = new WeakMap();
60
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAW,MAAM,QAAQ,CAAA;AAiBrD,MAAM,OAAO,gBAAiB,SAAQ,SAAS;IAI7C,YAAY,OAAgB,EAAE,OAAgC;QAC5D,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,eAAe,CAAA;QAEpD,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;QAN1B,yCAAe;QACf,4CAA2C;QAOzC,uBAAA,IAAI,6BAAY;YACd,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,EAAE;YAC5B,QAAQ;SACT,MAAA,CAAA;QAED,uBAAA,IAAI,0BAAS,IAAI,QAAQ,CAAC,IAAI,EAAE,eAAe,EAAE;YAC/C,aAAa,EAAE,IAAI;YACnB,GAAG,EAAE;gBACH,OAAO,EAAE,sCAAsC;gBAC/C,GAAG,uBAAA,IAAI,iCAAS,CAAC,MAAM;aACxB;SACF,CAAC,MAAA,CAAA;IACJ,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,iBAAyB;QAClC,uBAAA,IAAI,8BAAM,CAAC,UAAU,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAA;IACrD,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,iBAAyB;QAClC,uBAAA,IAAI,8BAAM,CAAC,UAAU,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAA;IACrD,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,QAAgB;QACtB,uBAAA,IAAI,8BAAM,CAAC,UAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;IAC1C,CAAC;IAED;;OAEG;IACH,YAAY,CAAC,IAAY;QACvB,uBAAA,IAAI,8BAAM,CAAC,UAAU,CAAC,YAAY,EAAE;YAClC,IAAI;SACL,CAAC,CAAA;IACJ,CAAC;CACF"}
package/license ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Filip Dupanović <filip.dupanovic@gmail.com> (https://langri-sha.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@langri-sha/projen-typescript-config",
3
+ "version": "0.1.0",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "main": "lib/index.js",
7
+ "scripts": {
8
+ "prepublishOnly": "rm -rf lib; tsc --project tsconfig.build.json"
9
+ },
10
+ "dependencies": {
11
+ "@schemastore/tsconfig": "0.0.11"
12
+ },
13
+ "devDependencies": {
14
+ "@langri-sha/jest-test": "0.7.1",
15
+ "@langri-sha/tsconfig": "0.9.0",
16
+ "@types/node": "20.12.11",
17
+ "projen": "0.81.10"
18
+ },
19
+ "peerDependencies": {
20
+ "projen": "^0.81.1"
21
+ },
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "types": "lib/index.d.ts"
26
+ }
package/readme ADDED
@@ -0,0 +1,45 @@
1
+ # @langri-sha/typescript-config
2
+
3
+ A [projen] component for managing [TSConfig] files for [TypeScript] projects.
4
+
5
+ Offers full support for configuring TypeScript via [`@schemastore/tsconfig`], as
6
+ well as a handful of helpers that make it easy to maintain several TypeScript
7
+ projects inside a monorepo.
8
+
9
+ ## Usage
10
+
11
+ Install required dependencies:
12
+
13
+ ```sh
14
+ npm install projen @langri-sha/typescript-config
15
+ ```
16
+
17
+ Create a TypeScript configuration for your project:
18
+
19
+ ```sh
20
+ import { Project } from 'projen'
21
+ import { TypeScriptConfig } from '@langri-sha/typescript-config'
22
+
23
+ const project = new Project({
24
+ name: 'test',
25
+ })
26
+
27
+ const tsconfig = new TypeScriptConfig(project)
28
+
29
+ const tsconfigBuild = new TypeScriptConfig(project, {
30
+ fileName: 'tsconfig.build.json',
31
+ config: {
32
+ extends: ['tsconfig.json'],
33
+ compilerOptions: {
34
+ target: 'es2020',
35
+ },
36
+ }
37
+ })
38
+
39
+ project.synth()
40
+ ```
41
+
42
+ [@schemastore/tsconfig]: https://github.com/schemastore/tsconfig
43
+ [projen]: https://projen.io/
44
+ [tsconfig]: https://www.typescriptlang.org/tsconfig.
45
+ [typescript]: https://www.typescriptlang.org/
package/src/index.ts ADDED
@@ -0,0 +1,71 @@
1
+ import type { JSONSchemaForTheTypeScriptCompilerSConfigurationFile } from '@schemastore/tsconfig'
2
+ import { Component, JsonFile, Project } from 'projen'
3
+
4
+ export interface TypeScriptConfigOptions {
5
+ config?: JSONSchemaForTheTypeScriptCompilerSConfigurationFile & {
6
+ /**
7
+ * Referenced projects. Requires TypeScript version 3.0 or later.
8
+ */
9
+ references?: {
10
+ /**
11
+ * Path to referenced tsconfig or to folder containing tsconfig.
12
+ */
13
+ path: string
14
+ }[]
15
+ }
16
+ fileName?: string
17
+ }
18
+
19
+ export class TypeScriptConfig extends Component {
20
+ #file: JsonFile
21
+ #options: Required<TypeScriptConfigOptions>
22
+
23
+ constructor(project: Project, options: TypeScriptConfigOptions) {
24
+ const fileName = options.fileName ?? 'tsconfig.json'
25
+
26
+ super(project, fileName)
27
+
28
+ this.#options = {
29
+ config: options.config ?? {},
30
+ fileName,
31
+ }
32
+
33
+ this.#file = new JsonFile(this, 'tsconfig.json', {
34
+ allowComments: true,
35
+ obj: {
36
+ $schema: 'http://json.schemastore.org/tsconfig',
37
+ ...this.#options.config,
38
+ },
39
+ })
40
+ }
41
+
42
+ /**
43
+ * Appends to the list of filenames and patterns to exclude in the program.
44
+ */
45
+ addExclude(fileNameOrPattern: string) {
46
+ this.#file.addToArray('exclude', fileNameOrPattern)
47
+ }
48
+
49
+ /**
50
+ * Appends to the list of filenames and patterns to include in the program.
51
+ */
52
+ addInclude(fileNameOrPattern: string) {
53
+ this.#file.addToArray('include', fileNameOrPattern)
54
+ }
55
+
56
+ /**
57
+ * Appends to the list of filenames to include in the program.
58
+ */
59
+ addFile(fileName: string) {
60
+ this.#file.addToArray('files', fileName)
61
+ }
62
+
63
+ /**
64
+ * Adds a reference project.
65
+ */
66
+ addReference(path: string) {
67
+ this.#file.addToArray('references', {
68
+ path,
69
+ })
70
+ }
71
+ }