@teambit/typescript 1.0.258 → 1.0.260
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/artifacts/__bit_junit.xml +18 -21
- package/artifacts/preview/teambit_typescript_typescript-preview.js +1 -1
- package/artifacts/schema.json +14779 -62
- package/dist/preview-1714620113654.js +7 -0
- package/dist/sourceFileTransformers/export.d.ts +1 -1
- package/dist/sourceFileTransformers/export.js.map +1 -1
- package/dist/sourceFileTransformers/expression-statement.d.ts +1 -1
- package/dist/sourceFileTransformers/expression-statement.js.map +1 -1
- package/dist/sourceFileTransformers/function.d.ts +1 -1
- package/dist/sourceFileTransformers/function.js.map +1 -1
- package/dist/sourceFileTransformers/import.d.ts +1 -1
- package/dist/sourceFileTransformers/import.js.map +1 -1
- package/dist/typescript.main.runtime.d.ts +1 -8
- package/dist/typescript.main.runtime.js +3 -41
- package/dist/typescript.main.runtime.js.map +1 -1
- package/package.json +20 -21
- package/sourceFileTransformers/export.ts +1 -1
- package/sourceFileTransformers/expression-statement.ts +1 -1
- package/sourceFileTransformers/function.ts +1 -1
- package/sourceFileTransformers/import.ts +1 -1
- package/cmds/write-tsconfig.cmd.ts +0 -75
- package/dist/cmds/write-tsconfig.cmd.d.ts +0 -26
- package/dist/cmds/write-tsconfig.cmd.js +0 -95
- package/dist/cmds/write-tsconfig.cmd.js.map +0 -1
- package/dist/dedupe-path.spec.d.ts +0 -1
- package/dist/dedupe-path.spec.js +0 -62
- package/dist/dedupe-path.spec.js.map +0 -1
- package/dist/preview-1714472366682.js +0 -7
- package/dist/tsconfig-writer.d.ts +0 -49
- package/dist/tsconfig-writer.js +0 -284
- package/dist/tsconfig-writer.js.map +0 -1
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { omit } from 'lodash';
|
|
3
|
-
import { Command, CommandOptions } from '@teambit/cli';
|
|
4
|
-
import chalk from 'chalk';
|
|
5
|
-
import { TypescriptMain } from '../typescript.main.runtime';
|
|
6
|
-
|
|
7
|
-
type Flags = { dryRun?: boolean; noDedupe?: boolean; dryRunWithTsconfig?: boolean; clean?: boolean; silent?: boolean };
|
|
8
|
-
|
|
9
|
-
export default class WriteTsconfigCmd implements Command {
|
|
10
|
-
name = 'write-tsconfig';
|
|
11
|
-
// description = 'EXPERIMENTAL. write tsconfig.json files in the component directories';
|
|
12
|
-
description = 'DEPRECATED. use bit ws-config write instead';
|
|
13
|
-
alias = '';
|
|
14
|
-
group = 'development';
|
|
15
|
-
private = true;
|
|
16
|
-
options = [
|
|
17
|
-
['c', 'clean', 'delete tsconfig files from the workspace. highly recommended to run it with "--dry-run" first'],
|
|
18
|
-
['s', 'silent', 'do not prompt for confirmation'],
|
|
19
|
-
['', 'no-dedupe', "write tsconfig.json inside each one of the component's dir, avoid deduping"],
|
|
20
|
-
['', 'dry-run', 'show the paths that tsconfig will be written per env'],
|
|
21
|
-
[
|
|
22
|
-
'',
|
|
23
|
-
'dry-run-with-tsconfig',
|
|
24
|
-
'use with --json flag. show the tsconfig.json content and the paths it will be written per env',
|
|
25
|
-
],
|
|
26
|
-
['j', 'json', 'json format'],
|
|
27
|
-
] as CommandOptions;
|
|
28
|
-
|
|
29
|
-
constructor(private tsMain: TypescriptMain) {}
|
|
30
|
-
|
|
31
|
-
async report(_args, flags: Flags) {
|
|
32
|
-
const { cleanResults, writeResults } = await this.json(_args, flags);
|
|
33
|
-
if (flags.dryRunWithTsconfig) {
|
|
34
|
-
throw new Error(`use --json flag along with --dry-run-with-tsconfig`);
|
|
35
|
-
}
|
|
36
|
-
const isDryRun = flags.dryRun;
|
|
37
|
-
const cleanResultsOutput = cleanResults
|
|
38
|
-
? `${chalk.green(`the following paths ${isDryRun ? 'will be' : 'were'} deleted`)}\n${cleanResults.join('\n')}\n\n`
|
|
39
|
-
: '';
|
|
40
|
-
|
|
41
|
-
const totalFiles = writeResults.map((r) => r.paths.length).reduce((acc, current) => acc + current);
|
|
42
|
-
const writeTitle = isDryRun
|
|
43
|
-
? chalk.green(`${totalFiles} files will be written`)
|
|
44
|
-
: chalk.green(`${totalFiles} files have been written successfully`);
|
|
45
|
-
const writeOutput = writeResults
|
|
46
|
-
.map((result) => {
|
|
47
|
-
const paths = result.paths
|
|
48
|
-
.map((p) => path.join(p, 'tsconfig.json'))
|
|
49
|
-
.map((str) => ` ${str}`)
|
|
50
|
-
.join('\n');
|
|
51
|
-
return `The following paths are according to env(s) ${chalk.bold(result.envIds.join(', '))}\n${paths}`;
|
|
52
|
-
})
|
|
53
|
-
.join('\n\n');
|
|
54
|
-
return `${cleanResultsOutput}${writeTitle}\n${writeOutput}`;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async json(_args, flags: Flags) {
|
|
58
|
-
const { clean, silent, noDedupe, dryRunWithTsconfig } = flags;
|
|
59
|
-
const dryRun = dryRunWithTsconfig ? true : flags.dryRun;
|
|
60
|
-
const { cleanResults, writeResults } = await this.tsMain.writeTsconfigJson({
|
|
61
|
-
clean,
|
|
62
|
-
dedupe: !noDedupe,
|
|
63
|
-
dryRun,
|
|
64
|
-
dryRunWithTsconfig,
|
|
65
|
-
silent,
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
if (dryRun) {
|
|
69
|
-
const writeJson = dryRunWithTsconfig ? writeResults : writeResults.map((s) => omit(s, ['tsconfig']));
|
|
70
|
-
// return JSON.stringify({ cleanResults, writeResults: writeJson }, undefined, 2);
|
|
71
|
-
return { cleanResults, writeResults: writeJson };
|
|
72
|
-
}
|
|
73
|
-
return { cleanResults, writeResults };
|
|
74
|
-
}
|
|
75
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/// <reference types="lodash" />
|
|
2
|
-
import { Command, CommandOptions } from '@teambit/cli';
|
|
3
|
-
import { TypescriptMain } from '../typescript.main.runtime';
|
|
4
|
-
type Flags = {
|
|
5
|
-
dryRun?: boolean;
|
|
6
|
-
noDedupe?: boolean;
|
|
7
|
-
dryRunWithTsconfig?: boolean;
|
|
8
|
-
clean?: boolean;
|
|
9
|
-
silent?: boolean;
|
|
10
|
-
};
|
|
11
|
-
export default class WriteTsconfigCmd implements Command {
|
|
12
|
-
private tsMain;
|
|
13
|
-
name: string;
|
|
14
|
-
description: string;
|
|
15
|
-
alias: string;
|
|
16
|
-
group: string;
|
|
17
|
-
private: boolean;
|
|
18
|
-
options: CommandOptions;
|
|
19
|
-
constructor(tsMain: TypescriptMain);
|
|
20
|
-
report(_args: any, flags: Flags): Promise<string>;
|
|
21
|
-
json(_args: any, flags: Flags): Promise<{
|
|
22
|
-
cleanResults: string[] | undefined;
|
|
23
|
-
writeResults: import("lodash").Omit<import("../tsconfig-writer").TsconfigPathsPerEnv, "tsconfig">[];
|
|
24
|
-
}>;
|
|
25
|
-
}
|
|
26
|
-
export {};
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
function _path() {
|
|
8
|
-
const data = _interopRequireDefault(require("path"));
|
|
9
|
-
_path = function () {
|
|
10
|
-
return data;
|
|
11
|
-
};
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
function _lodash() {
|
|
15
|
-
const data = require("lodash");
|
|
16
|
-
_lodash = function () {
|
|
17
|
-
return data;
|
|
18
|
-
};
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
|
-
function _chalk() {
|
|
22
|
-
const data = _interopRequireDefault(require("chalk"));
|
|
23
|
-
_chalk = function () {
|
|
24
|
-
return data;
|
|
25
|
-
};
|
|
26
|
-
return data;
|
|
27
|
-
}
|
|
28
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
30
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
31
|
-
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
32
|
-
class WriteTsconfigCmd {
|
|
33
|
-
constructor(tsMain) {
|
|
34
|
-
this.tsMain = tsMain;
|
|
35
|
-
_defineProperty(this, "name", 'write-tsconfig');
|
|
36
|
-
// description = 'EXPERIMENTAL. write tsconfig.json files in the component directories';
|
|
37
|
-
_defineProperty(this, "description", 'DEPRECATED. use bit ws-config write instead');
|
|
38
|
-
_defineProperty(this, "alias", '');
|
|
39
|
-
_defineProperty(this, "group", 'development');
|
|
40
|
-
_defineProperty(this, "private", true);
|
|
41
|
-
_defineProperty(this, "options", [['c', 'clean', 'delete tsconfig files from the workspace. highly recommended to run it with "--dry-run" first'], ['s', 'silent', 'do not prompt for confirmation'], ['', 'no-dedupe', "write tsconfig.json inside each one of the component's dir, avoid deduping"], ['', 'dry-run', 'show the paths that tsconfig will be written per env'], ['', 'dry-run-with-tsconfig', 'use with --json flag. show the tsconfig.json content and the paths it will be written per env'], ['j', 'json', 'json format']]);
|
|
42
|
-
}
|
|
43
|
-
async report(_args, flags) {
|
|
44
|
-
const {
|
|
45
|
-
cleanResults,
|
|
46
|
-
writeResults
|
|
47
|
-
} = await this.json(_args, flags);
|
|
48
|
-
if (flags.dryRunWithTsconfig) {
|
|
49
|
-
throw new Error(`use --json flag along with --dry-run-with-tsconfig`);
|
|
50
|
-
}
|
|
51
|
-
const isDryRun = flags.dryRun;
|
|
52
|
-
const cleanResultsOutput = cleanResults ? `${_chalk().default.green(`the following paths ${isDryRun ? 'will be' : 'were'} deleted`)}\n${cleanResults.join('\n')}\n\n` : '';
|
|
53
|
-
const totalFiles = writeResults.map(r => r.paths.length).reduce((acc, current) => acc + current);
|
|
54
|
-
const writeTitle = isDryRun ? _chalk().default.green(`${totalFiles} files will be written`) : _chalk().default.green(`${totalFiles} files have been written successfully`);
|
|
55
|
-
const writeOutput = writeResults.map(result => {
|
|
56
|
-
const paths = result.paths.map(p => _path().default.join(p, 'tsconfig.json')).map(str => ` ${str}`).join('\n');
|
|
57
|
-
return `The following paths are according to env(s) ${_chalk().default.bold(result.envIds.join(', '))}\n${paths}`;
|
|
58
|
-
}).join('\n\n');
|
|
59
|
-
return `${cleanResultsOutput}${writeTitle}\n${writeOutput}`;
|
|
60
|
-
}
|
|
61
|
-
async json(_args, flags) {
|
|
62
|
-
const {
|
|
63
|
-
clean,
|
|
64
|
-
silent,
|
|
65
|
-
noDedupe,
|
|
66
|
-
dryRunWithTsconfig
|
|
67
|
-
} = flags;
|
|
68
|
-
const dryRun = dryRunWithTsconfig ? true : flags.dryRun;
|
|
69
|
-
const {
|
|
70
|
-
cleanResults,
|
|
71
|
-
writeResults
|
|
72
|
-
} = await this.tsMain.writeTsconfigJson({
|
|
73
|
-
clean,
|
|
74
|
-
dedupe: !noDedupe,
|
|
75
|
-
dryRun,
|
|
76
|
-
dryRunWithTsconfig,
|
|
77
|
-
silent
|
|
78
|
-
});
|
|
79
|
-
if (dryRun) {
|
|
80
|
-
const writeJson = dryRunWithTsconfig ? writeResults : writeResults.map(s => (0, _lodash().omit)(s, ['tsconfig']));
|
|
81
|
-
// return JSON.stringify({ cleanResults, writeResults: writeJson }, undefined, 2);
|
|
82
|
-
return {
|
|
83
|
-
cleanResults,
|
|
84
|
-
writeResults: writeJson
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
return {
|
|
88
|
-
cleanResults,
|
|
89
|
-
writeResults
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
exports.default = WriteTsconfigCmd;
|
|
94
|
-
|
|
95
|
-
//# sourceMappingURL=write-tsconfig.cmd.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_path","data","_interopRequireDefault","require","_lodash","_chalk","obj","__esModule","default","_defineProperty","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","t","i","_toPrimitive","r","e","Symbol","toPrimitive","call","TypeError","String","Number","WriteTsconfigCmd","constructor","tsMain","report","_args","flags","cleanResults","writeResults","json","dryRunWithTsconfig","Error","isDryRun","dryRun","cleanResultsOutput","chalk","green","join","totalFiles","map","paths","length","reduce","acc","current","writeTitle","writeOutput","result","p","path","str","bold","envIds","clean","silent","noDedupe","writeTsconfigJson","dedupe","writeJson","s","omit","exports"],"sources":["write-tsconfig.cmd.ts"],"sourcesContent":["import path from 'path';\nimport { omit } from 'lodash';\nimport { Command, CommandOptions } from '@teambit/cli';\nimport chalk from 'chalk';\nimport { TypescriptMain } from '../typescript.main.runtime';\n\ntype Flags = { dryRun?: boolean; noDedupe?: boolean; dryRunWithTsconfig?: boolean; clean?: boolean; silent?: boolean };\n\nexport default class WriteTsconfigCmd implements Command {\n name = 'write-tsconfig';\n // description = 'EXPERIMENTAL. write tsconfig.json files in the component directories';\n description = 'DEPRECATED. use bit ws-config write instead';\n alias = '';\n group = 'development';\n private = true;\n options = [\n ['c', 'clean', 'delete tsconfig files from the workspace. highly recommended to run it with \"--dry-run\" first'],\n ['s', 'silent', 'do not prompt for confirmation'],\n ['', 'no-dedupe', \"write tsconfig.json inside each one of the component's dir, avoid deduping\"],\n ['', 'dry-run', 'show the paths that tsconfig will be written per env'],\n [\n '',\n 'dry-run-with-tsconfig',\n 'use with --json flag. show the tsconfig.json content and the paths it will be written per env',\n ],\n ['j', 'json', 'json format'],\n ] as CommandOptions;\n\n constructor(private tsMain: TypescriptMain) {}\n\n async report(_args, flags: Flags) {\n const { cleanResults, writeResults } = await this.json(_args, flags);\n if (flags.dryRunWithTsconfig) {\n throw new Error(`use --json flag along with --dry-run-with-tsconfig`);\n }\n const isDryRun = flags.dryRun;\n const cleanResultsOutput = cleanResults\n ? `${chalk.green(`the following paths ${isDryRun ? 'will be' : 'were'} deleted`)}\\n${cleanResults.join('\\n')}\\n\\n`\n : '';\n\n const totalFiles = writeResults.map((r) => r.paths.length).reduce((acc, current) => acc + current);\n const writeTitle = isDryRun\n ? chalk.green(`${totalFiles} files will be written`)\n : chalk.green(`${totalFiles} files have been written successfully`);\n const writeOutput = writeResults\n .map((result) => {\n const paths = result.paths\n .map((p) => path.join(p, 'tsconfig.json'))\n .map((str) => ` ${str}`)\n .join('\\n');\n return `The following paths are according to env(s) ${chalk.bold(result.envIds.join(', '))}\\n${paths}`;\n })\n .join('\\n\\n');\n return `${cleanResultsOutput}${writeTitle}\\n${writeOutput}`;\n }\n\n async json(_args, flags: Flags) {\n const { clean, silent, noDedupe, dryRunWithTsconfig } = flags;\n const dryRun = dryRunWithTsconfig ? true : flags.dryRun;\n const { cleanResults, writeResults } = await this.tsMain.writeTsconfigJson({\n clean,\n dedupe: !noDedupe,\n dryRun,\n dryRunWithTsconfig,\n silent,\n });\n\n if (dryRun) {\n const writeJson = dryRunWithTsconfig ? writeResults : writeResults.map((s) => omit(s, ['tsconfig']));\n // return JSON.stringify({ cleanResults, writeResults: writeJson }, undefined, 2);\n return { cleanResults, writeResults: writeJson };\n }\n return { cleanResults, writeResults };\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,MAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,KAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,QAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,OAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAI,OAAA;EAAA,MAAAJ,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAE,MAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,I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
|
-
const data = require("chai");
|
|
5
|
-
_chai = function () {
|
|
6
|
-
return data;
|
|
7
|
-
};
|
|
8
|
-
return data;
|
|
9
|
-
}
|
|
10
|
-
function _tsconfigWriter() {
|
|
11
|
-
const data = require("./tsconfig-writer");
|
|
12
|
-
_tsconfigWriter = function () {
|
|
13
|
-
return data;
|
|
14
|
-
};
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
describe('dedupePath', () => {
|
|
18
|
-
it('should return the root-dir if there is only one env involved', () => {
|
|
19
|
-
const input = [{
|
|
20
|
-
ids: ['env1'],
|
|
21
|
-
paths: ['p1/e1, p2']
|
|
22
|
-
}];
|
|
23
|
-
const output = (0, _tsconfigWriter().dedupePaths)(input);
|
|
24
|
-
(0, _chai().expect)(output).to.deep.equal([{
|
|
25
|
-
ids: ['env1'],
|
|
26
|
-
paths: ['.']
|
|
27
|
-
}]);
|
|
28
|
-
});
|
|
29
|
-
it('should set the env with the most components', () => {
|
|
30
|
-
const input = [{
|
|
31
|
-
ids: ['env1'],
|
|
32
|
-
paths: ['p1/e1', 'p1/e2']
|
|
33
|
-
}, {
|
|
34
|
-
ids: ['env2'],
|
|
35
|
-
paths: ['p1/e3']
|
|
36
|
-
}];
|
|
37
|
-
const output = (0, _tsconfigWriter().dedupePaths)(input);
|
|
38
|
-
// @ts-ignore
|
|
39
|
-
(0, _chai().expect)(output).to.deep.equal([{
|
|
40
|
-
ids: ['env2'],
|
|
41
|
-
paths: ['p1/e3']
|
|
42
|
-
}, {
|
|
43
|
-
ids: ['env1'],
|
|
44
|
-
paths: ['.']
|
|
45
|
-
}]);
|
|
46
|
-
});
|
|
47
|
-
it('should not set any env to a shared dir if it no env has max components', () => {
|
|
48
|
-
const input = [{
|
|
49
|
-
ids: ['env1'],
|
|
50
|
-
paths: ['p1/e1']
|
|
51
|
-
}, {
|
|
52
|
-
ids: ['env2'],
|
|
53
|
-
paths: ['p1/e2']
|
|
54
|
-
}];
|
|
55
|
-
const output = (0, _tsconfigWriter().dedupePaths)(input);
|
|
56
|
-
(0, _chai().expect)(output.length).to.equal(2);
|
|
57
|
-
// @ts-ignore
|
|
58
|
-
(0, _chai().expect)(output).to.deep.equal(input);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
//# sourceMappingURL=dedupe-path.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_chai","data","require","_tsconfigWriter","describe","it","input","ids","paths","output","dedupePaths","expect","to","deep","equal","length"],"sources":["dedupe-path.spec.ts"],"sourcesContent":["import { expect } from 'chai';\nimport { dedupePaths } from './tsconfig-writer';\n\ndescribe('dedupePath', () => {\n it('should return the root-dir if there is only one env involved', () => {\n const input = [{ ids: ['env1'], paths: ['p1/e1, p2'] }];\n const output = dedupePaths(input);\n expect(output).to.deep.equal([{ ids: ['env1'], paths: ['.'] }]);\n });\n it('should set the env with the most components', () => {\n const input = [\n { ids: ['env1'], paths: ['p1/e1', 'p1/e2'] },\n { ids: ['env2'], paths: ['p1/e3'] },\n ];\n const output = dedupePaths(input);\n // @ts-ignore\n expect(output).to.deep.equal([\n { ids: ['env2'], paths: ['p1/e3'] },\n { ids: ['env1'], paths: ['.'] },\n ]);\n });\n it('should not set any env to a shared dir if it no env has max components', () => {\n const input = [\n { ids: ['env1'], paths: ['p1/e1'] },\n { ids: ['env2'], paths: ['p1/e2'] },\n ];\n const output = dedupePaths(input);\n expect(output.length).to.equal(2);\n // @ts-ignore\n expect(output).to.deep.equal(input);\n });\n});\n"],"mappings":";;AAAA,SAAAA,MAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,KAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,gBAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,eAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEAG,QAAQ,CAAC,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KAAK,EAAE,CAAC,OAAO;IAAE,CAAC,CACpC;IACD,MAAMC,MAAM,GAAG,IAAAC,6BAAW,EAACJ,KAAK,CAAC;IACjC,IAAAK,cAAM,EAACF,MAAM,CAACM,MAAM,CAAC,CAACH,EAAE,CAACE,KAAK,CAAC,CAAC,CAAC;IACjC;IACA,IAAAH,cAAM,EAACF,MAAM,CAAC,CAACG,EAAE,CAACC,IAAI,CAACC,KAAK,CAACR,KAAK,CAAC;EACrC,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import * as compositions_0 from '/Users/giladshoham/Library/Caches/Bit/capsules/root/b5ea46ec3/teambit.typescript_typescript@1.0.258/dist/typescript.composition.js';
|
|
2
|
-
import * as overview_0 from '/Users/giladshoham/Library/Caches/Bit/capsules/root/b5ea46ec3/teambit.typescript_typescript@1.0.258/dist/typescript.docs.mdx';
|
|
3
|
-
|
|
4
|
-
export const compositions = [compositions_0];
|
|
5
|
-
export const overview = [overview_0];
|
|
6
|
-
|
|
7
|
-
export const compositions_metadata = {"compositions":[{"displayName":"Logo","identifier":"Logo"}]};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { ExecutionContext } from '@teambit/envs';
|
|
2
|
-
import { Workspace } from '@teambit/workspace';
|
|
3
|
-
import { Logger } from '@teambit/logger';
|
|
4
|
-
import { TsconfigWriterOptions } from './typescript.main.runtime';
|
|
5
|
-
export type TsconfigPathsPerEnv = {
|
|
6
|
-
envIds: string[];
|
|
7
|
-
tsconfig: string;
|
|
8
|
-
paths: string[];
|
|
9
|
-
};
|
|
10
|
-
export declare class TsconfigWriter {
|
|
11
|
-
private workspace;
|
|
12
|
-
private logger;
|
|
13
|
-
constructor(workspace: Workspace, logger: Logger);
|
|
14
|
-
write(envsExecutionContext: ExecutionContext[], options: TsconfigWriterOptions): Promise<TsconfigPathsPerEnv[]>;
|
|
15
|
-
private getTsconfigFromEnv;
|
|
16
|
-
clean(envsExecutionContext: ExecutionContext[], { dryRun, silent }: TsconfigWriterOptions): Promise<string[]>;
|
|
17
|
-
private promptForWriting;
|
|
18
|
-
private promptForCleaning;
|
|
19
|
-
private deleteFiles;
|
|
20
|
-
private writeFiles;
|
|
21
|
-
private getPathsPerEnv;
|
|
22
|
-
}
|
|
23
|
-
type PathsPerEnvIds = {
|
|
24
|
-
ids: string[];
|
|
25
|
-
paths: string[];
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* easier to understand by an example:
|
|
29
|
-
* input:
|
|
30
|
-
* [
|
|
31
|
-
* { id: react, paths: [ui/button, ui/form] },
|
|
32
|
-
* { id: aspect, paths: [p/a1, p/a2] },
|
|
33
|
-
* { id: node, paths: [p/n1] },
|
|
34
|
-
* ]
|
|
35
|
-
*
|
|
36
|
-
* output:
|
|
37
|
-
* [
|
|
38
|
-
* { id: react, paths: [ui] },
|
|
39
|
-
* { id: aspect, paths: [p] },
|
|
40
|
-
* { id: node, paths: [p/n1] },
|
|
41
|
-
* ]
|
|
42
|
-
*
|
|
43
|
-
* the goal is to minimize the amount of files to write per env if possible.
|
|
44
|
-
* when multiple components of the same env share a root-dir, then, it's enough to write a file in that shared dir.
|
|
45
|
-
* if in a shared-dir, some components using env1 and some env2, it finds the env that has the max number of
|
|
46
|
-
* components, this env will be optimized. other components, will have the files written inside their dirs.
|
|
47
|
-
*/
|
|
48
|
-
export declare function dedupePaths(pathsPerEnvId: PathsPerEnvIds[]): PathsPerEnvIds[];
|
|
49
|
-
export {};
|
package/dist/tsconfig-writer.js
DELETED
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.TsconfigWriter = void 0;
|
|
7
|
-
exports.dedupePaths = dedupePaths;
|
|
8
|
-
function _fsExtra() {
|
|
9
|
-
const data = _interopRequireDefault(require("fs-extra"));
|
|
10
|
-
_fsExtra = function () {
|
|
11
|
-
return data;
|
|
12
|
-
};
|
|
13
|
-
return data;
|
|
14
|
-
}
|
|
15
|
-
function _path() {
|
|
16
|
-
const data = _interopRequireDefault(require("path"));
|
|
17
|
-
_path = function () {
|
|
18
|
-
return data;
|
|
19
|
-
};
|
|
20
|
-
return data;
|
|
21
|
-
}
|
|
22
|
-
function _yesno() {
|
|
23
|
-
const data = _interopRequireDefault(require("yesno"));
|
|
24
|
-
_yesno = function () {
|
|
25
|
-
return data;
|
|
26
|
-
};
|
|
27
|
-
return data;
|
|
28
|
-
}
|
|
29
|
-
function _lodash() {
|
|
30
|
-
const data = require("lodash");
|
|
31
|
-
_lodash = function () {
|
|
32
|
-
return data;
|
|
33
|
-
};
|
|
34
|
-
return data;
|
|
35
|
-
}
|
|
36
|
-
function _exceptions() {
|
|
37
|
-
const data = require("@teambit/legacy/dist/prompts/exceptions");
|
|
38
|
-
_exceptions = function () {
|
|
39
|
-
return data;
|
|
40
|
-
};
|
|
41
|
-
return data;
|
|
42
|
-
}
|
|
43
|
-
function _chalk() {
|
|
44
|
-
const data = _interopRequireDefault(require("chalk"));
|
|
45
|
-
_chalk = function () {
|
|
46
|
-
return data;
|
|
47
|
-
};
|
|
48
|
-
return data;
|
|
49
|
-
}
|
|
50
|
-
function _() {
|
|
51
|
-
const data = require(".");
|
|
52
|
-
_ = function () {
|
|
53
|
-
return data;
|
|
54
|
-
};
|
|
55
|
-
return data;
|
|
56
|
-
}
|
|
57
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
58
|
-
class TsconfigWriter {
|
|
59
|
-
constructor(workspace, logger) {
|
|
60
|
-
this.workspace = workspace;
|
|
61
|
-
this.logger = logger;
|
|
62
|
-
}
|
|
63
|
-
async write(envsExecutionContext, options) {
|
|
64
|
-
const pathsPerEnvs = this.getPathsPerEnv(envsExecutionContext, options);
|
|
65
|
-
const tsconfigPathsPerEnv = pathsPerEnvs.map(pathsPerEnv => ({
|
|
66
|
-
envIds: pathsPerEnv.ids,
|
|
67
|
-
tsconfig: this.getTsconfigFromEnv(pathsPerEnv.env),
|
|
68
|
-
// pathsPerEnv.env.getTsConfig(),
|
|
69
|
-
paths: pathsPerEnv.paths
|
|
70
|
-
}));
|
|
71
|
-
if (options.dryRun) return tsconfigPathsPerEnv;
|
|
72
|
-
if (!options.silent) await this.promptForWriting(tsconfigPathsPerEnv.map(p => p.paths).flat());
|
|
73
|
-
await this.writeFiles(tsconfigPathsPerEnv);
|
|
74
|
-
return tsconfigPathsPerEnv;
|
|
75
|
-
}
|
|
76
|
-
getTsconfigFromEnv(env) {
|
|
77
|
-
const compiler = env.getCompiler();
|
|
78
|
-
if (compiler.id === _().TypescriptAspect.id) {
|
|
79
|
-
return compiler.displayConfig();
|
|
80
|
-
}
|
|
81
|
-
return JSON.stringify(env.getTsConfig(), undefined, 2);
|
|
82
|
-
}
|
|
83
|
-
async clean(envsExecutionContext, {
|
|
84
|
-
dryRun,
|
|
85
|
-
silent
|
|
86
|
-
}) {
|
|
87
|
-
const pathsPerEnvs = this.getPathsPerEnv(envsExecutionContext, {
|
|
88
|
-
dedupe: false
|
|
89
|
-
});
|
|
90
|
-
const componentPaths = pathsPerEnvs.map(p => p.paths).flat();
|
|
91
|
-
const allPossibleDirs = getAllPossibleDirsFromPaths(componentPaths);
|
|
92
|
-
const dirsWithTsconfig = await filterDirsWithTsconfigFile(allPossibleDirs);
|
|
93
|
-
const tsconfigFiles = dirsWithTsconfig.map(dir => _path().default.join(dir, 'tsconfig.json'));
|
|
94
|
-
if (dryRun) return tsconfigFiles;
|
|
95
|
-
if (!dirsWithTsconfig.length) return [];
|
|
96
|
-
if (!silent) await this.promptForCleaning(tsconfigFiles);
|
|
97
|
-
await this.deleteFiles(tsconfigFiles);
|
|
98
|
-
return tsconfigFiles;
|
|
99
|
-
}
|
|
100
|
-
async promptForWriting(dirs) {
|
|
101
|
-
this.logger.clearStatusLine();
|
|
102
|
-
const tsconfigFiles = dirs.map(dir => _path().default.join(dir, 'tsconfig.json'));
|
|
103
|
-
const ok = await (0, _yesno().default)({
|
|
104
|
-
question: `${_chalk().default.underline('The following paths will be written:')}
|
|
105
|
-
${tsconfigFiles.join('\n')}
|
|
106
|
-
${_chalk().default.bold('Do you want to continue? [yes(y)/no(n)]')}`
|
|
107
|
-
});
|
|
108
|
-
if (!ok) {
|
|
109
|
-
throw new (_exceptions().PromptCanceled)();
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
async promptForCleaning(tsconfigFiles) {
|
|
113
|
-
this.logger.clearStatusLine();
|
|
114
|
-
const ok = await (0, _yesno().default)({
|
|
115
|
-
question: `${_chalk().default.underline('The following paths will be deleted:')}
|
|
116
|
-
${tsconfigFiles.join('\n')}
|
|
117
|
-
${_chalk().default.bold('Do you want to continue? [yes(y)/no(n)]')}`
|
|
118
|
-
});
|
|
119
|
-
if (!ok) {
|
|
120
|
-
throw new (_exceptions().PromptCanceled)();
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
async deleteFiles(tsconfigFiles) {
|
|
124
|
-
await Promise.all(tsconfigFiles.map(f => _fsExtra().default.remove(f)));
|
|
125
|
-
}
|
|
126
|
-
async writeFiles(tsconfigPathsPerEnvs) {
|
|
127
|
-
await Promise.all(tsconfigPathsPerEnvs.map(pathsPerEnv => {
|
|
128
|
-
return Promise.all(pathsPerEnv.paths.map(p => _fsExtra().default.writeFile(_path().default.join(p, 'tsconfig.json'), pathsPerEnv.tsconfig)));
|
|
129
|
-
}));
|
|
130
|
-
}
|
|
131
|
-
getPathsPerEnv(envsExecutionContext, {
|
|
132
|
-
dedupe
|
|
133
|
-
}) {
|
|
134
|
-
const pathsPerEnvs = envsExecutionContext.map(envExecution => {
|
|
135
|
-
return {
|
|
136
|
-
id: envExecution.id,
|
|
137
|
-
env: envExecution.env,
|
|
138
|
-
paths: envExecution.components.map(c => this.workspace.componentDir(c.id, undefined, {
|
|
139
|
-
relative: true
|
|
140
|
-
}))
|
|
141
|
-
};
|
|
142
|
-
});
|
|
143
|
-
if (!dedupe) {
|
|
144
|
-
return pathsPerEnvs.map(({
|
|
145
|
-
id,
|
|
146
|
-
env,
|
|
147
|
-
paths
|
|
148
|
-
}) => ({
|
|
149
|
-
ids: [id],
|
|
150
|
-
env,
|
|
151
|
-
paths
|
|
152
|
-
}));
|
|
153
|
-
}
|
|
154
|
-
const envsWithFiles = envsExecutionContext.map(e => ({
|
|
155
|
-
id: e.id,
|
|
156
|
-
file: e.env.getTsConfig()
|
|
157
|
-
}));
|
|
158
|
-
const envsPerFile = [];
|
|
159
|
-
const isEnvProcessed = envId => envsPerFile.map(e => e.envIds).flat().find(e => e === envId);
|
|
160
|
-
envsWithFiles.forEach(({
|
|
161
|
-
id,
|
|
162
|
-
file
|
|
163
|
-
}) => {
|
|
164
|
-
if (isEnvProcessed(id)) return;
|
|
165
|
-
const foundSameFile = envsWithFiles.filter(e => (0, _lodash().isEqual)(file, e.file));
|
|
166
|
-
envsPerFile.push({
|
|
167
|
-
envIds: foundSameFile.map(f => f.id),
|
|
168
|
-
fileContent: file
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
const pathsPerEnvIds = envsPerFile.map(e => ({
|
|
172
|
-
ids: e.envIds,
|
|
173
|
-
paths: (0, _lodash().compact)(e.envIds.map(envId => pathsPerEnvs.find(p => p.id === envId)?.paths).flat())
|
|
174
|
-
}));
|
|
175
|
-
// const pathsPerEnvIds = pathsPerEnvs.map((p) => ({ ids: p.ids, paths: p.paths }));
|
|
176
|
-
const envsPerDedupedPaths = dedupePaths(pathsPerEnvIds);
|
|
177
|
-
const dedupedPathsPerEnvs = envsPerDedupedPaths.map(envWithDedupePaths => {
|
|
178
|
-
const found = pathsPerEnvs.find(p => envWithDedupePaths.ids.includes(p.id));
|
|
179
|
-
if (!found) throw new Error(`dedupedPathsPerEnvs, unable to find ${envWithDedupePaths.ids}`);
|
|
180
|
-
return {
|
|
181
|
-
env: found.env,
|
|
182
|
-
ids: envWithDedupePaths.ids,
|
|
183
|
-
paths: envWithDedupePaths.paths
|
|
184
|
-
};
|
|
185
|
-
});
|
|
186
|
-
return dedupedPathsPerEnvs;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
exports.TsconfigWriter = TsconfigWriter;
|
|
190
|
-
async function filterDirsWithTsconfigFile(dirs) {
|
|
191
|
-
const dirsWithTsconfig = await Promise.all(dirs.map(async dir => {
|
|
192
|
-
const hasTsconfig = await _fsExtra().default.pathExists(_path().default.join(dir, 'tsconfig.json'));
|
|
193
|
-
return hasTsconfig ? dir : undefined;
|
|
194
|
-
}));
|
|
195
|
-
return (0, _lodash().compact)(dirsWithTsconfig);
|
|
196
|
-
}
|
|
197
|
-
function getAllPossibleDirsFromPaths(paths) {
|
|
198
|
-
const dirs = paths.map(p => getAllParentsDirOfPath(p)).flat();
|
|
199
|
-
dirs.push('.'); // add the root dir
|
|
200
|
-
return (0, _lodash().uniq)(dirs);
|
|
201
|
-
}
|
|
202
|
-
function getAllParentsDirOfPath(p) {
|
|
203
|
-
const all = [];
|
|
204
|
-
let current = p;
|
|
205
|
-
while (current !== '.') {
|
|
206
|
-
all.push(current);
|
|
207
|
-
current = _path().default.dirname(current);
|
|
208
|
-
}
|
|
209
|
-
return all;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* easier to understand by an example:
|
|
214
|
-
* input:
|
|
215
|
-
* [
|
|
216
|
-
* { id: react, paths: [ui/button, ui/form] },
|
|
217
|
-
* { id: aspect, paths: [p/a1, p/a2] },
|
|
218
|
-
* { id: node, paths: [p/n1] },
|
|
219
|
-
* ]
|
|
220
|
-
*
|
|
221
|
-
* output:
|
|
222
|
-
* [
|
|
223
|
-
* { id: react, paths: [ui] },
|
|
224
|
-
* { id: aspect, paths: [p] },
|
|
225
|
-
* { id: node, paths: [p/n1] },
|
|
226
|
-
* ]
|
|
227
|
-
*
|
|
228
|
-
* the goal is to minimize the amount of files to write per env if possible.
|
|
229
|
-
* when multiple components of the same env share a root-dir, then, it's enough to write a file in that shared dir.
|
|
230
|
-
* if in a shared-dir, some components using env1 and some env2, it finds the env that has the max number of
|
|
231
|
-
* components, this env will be optimized. other components, will have the files written inside their dirs.
|
|
232
|
-
*/
|
|
233
|
-
function dedupePaths(pathsPerEnvId) {
|
|
234
|
-
const rootDir = '.';
|
|
235
|
-
const individualPathPerConcatenatedEnvIds = pathsPerEnvId.reduce((acc, current) => {
|
|
236
|
-
current.paths.forEach(p => {
|
|
237
|
-
acc[p] = current.ids.join(',');
|
|
238
|
-
});
|
|
239
|
-
return acc;
|
|
240
|
-
}, {});
|
|
241
|
-
const allPaths = Object.keys(individualPathPerConcatenatedEnvIds);
|
|
242
|
-
const allPossibleDirs = getAllPossibleDirsFromPaths(allPaths);
|
|
243
|
-
const allPathsPerEnvId = {}; // null when parent-dir has same amount of comps per env.
|
|
244
|
-
|
|
245
|
-
const calculateBestEnvForDir = dir => {
|
|
246
|
-
if (individualPathPerConcatenatedEnvIds[dir]) {
|
|
247
|
-
// it's the component dir, so it's the best env
|
|
248
|
-
allPathsPerEnvId[dir] = individualPathPerConcatenatedEnvIds[dir];
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
const allPathsShareSameDir = dir === rootDir ? allPaths : allPaths.filter(p => p.startsWith(`${dir}/`));
|
|
252
|
-
const countPerEnv = {};
|
|
253
|
-
allPathsShareSameDir.forEach(p => {
|
|
254
|
-
const envIdStr = individualPathPerConcatenatedEnvIds[p];
|
|
255
|
-
if (countPerEnv[envIdStr]) countPerEnv[envIdStr] += 1;else countPerEnv[envIdStr] = 1;
|
|
256
|
-
});
|
|
257
|
-
const max = Math.max(...Object.values(countPerEnv));
|
|
258
|
-
const envWithMax = Object.keys(countPerEnv).filter(env => countPerEnv[env] === max);
|
|
259
|
-
if (!envWithMax.length) throw new Error(`must be at least one env related to path "${dir}"`);
|
|
260
|
-
if (envWithMax.length > 1) allPathsPerEnvId[dir] = null;else allPathsPerEnvId[dir] = envWithMax[0];
|
|
261
|
-
};
|
|
262
|
-
allPossibleDirs.forEach(dirPath => {
|
|
263
|
-
calculateBestEnvForDir(dirPath);
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
// this is the actual deduping. if found a shorter path with the same env, then no need for this path.
|
|
267
|
-
// in other words, return only the paths that their parent is null or has a different env.
|
|
268
|
-
const dedupedPathsPerEnvIds = Object.keys(allPathsPerEnvId).reduce((acc, current) => {
|
|
269
|
-
if (allPathsPerEnvId[current] && allPathsPerEnvId[_path().default.dirname(current)] !== allPathsPerEnvId[current]) {
|
|
270
|
-
acc[current] = allPathsPerEnvId[current];
|
|
271
|
-
}
|
|
272
|
-
return acc;
|
|
273
|
-
}, {});
|
|
274
|
-
// rootDir parent is always rootDir, so leave it as is.
|
|
275
|
-
if (allPathsPerEnvId[rootDir]) dedupedPathsPerEnvIds[rootDir] = allPathsPerEnvId[rootDir];
|
|
276
|
-
const envIdsPerDedupedPaths = (0, _lodash().invertBy)(dedupedPathsPerEnvIds);
|
|
277
|
-
const dedupedPaths = Object.keys(envIdsPerDedupedPaths).map(envIdStr => ({
|
|
278
|
-
ids: envIdStr.split(','),
|
|
279
|
-
paths: envIdsPerDedupedPaths[envIdStr]
|
|
280
|
-
}));
|
|
281
|
-
return dedupedPaths;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
//# sourceMappingURL=tsconfig-writer.js.map
|