@atlaspack/ts-utils 2.14.1-canary.32 → 2.14.1-canary.320
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.md +94 -0
- package/dist/CompilerHost.js +84 -0
- package/dist/FSHost.js +83 -0
- package/dist/LanguageServiceHost.js +51 -0
- package/dist/ParseConfigHost.js +17 -0
- package/dist/index.js +13 -0
- package/dist/loadTSConfig.js +23 -0
- package/lib/CompilerHost.js +7 -1
- package/lib/FSHost.js +4 -1
- package/lib/LanguageServiceHost.js +3 -3
- package/lib/ParseConfigHost.js +2 -0
- package/lib/types/CompilerHost.d.ts +19 -0
- package/lib/types/FSHost.d.ts +16 -0
- package/lib/types/LanguageServiceHost.d.ts +16 -0
- package/lib/types/ParseConfigHost.d.ts +9 -0
- package/lib/types/index.d.ts +5 -0
- package/lib/types/loadTSConfig.d.ts +2 -0
- package/package.json +10 -5
- package/src/{CompilerHost.js → CompilerHost.ts} +19 -11
- package/src/{FSHost.js → FSHost.ts} +23 -24
- package/src/{LanguageServiceHost.js → LanguageServiceHost.ts} +13 -9
- package/src/{ParseConfigHost.js → ParseConfigHost.ts} +4 -5
- package/src/{index.js → index.ts} +0 -1
- package/src/{loadTSConfig.js → loadTSConfig.ts} +2 -3
- package/tsconfig.json +12 -0
- package/tsconfig.tsbuildinfo +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,99 @@
|
|
|
1
1
|
# @atlaspack/ts-utils
|
|
2
2
|
|
|
3
|
+
## 2.14.14
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`c372f3f`](https://github.com/atlassian-labs/atlaspack/commit/c372f3fd6fce8200d5cf47f41bc7895c6cbb5558)]:
|
|
8
|
+
- @atlaspack/types-internal@2.20.5
|
|
9
|
+
|
|
10
|
+
## 2.14.13
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies []:
|
|
15
|
+
- @atlaspack/types-internal@2.20.4
|
|
16
|
+
|
|
17
|
+
## 2.14.12
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies []:
|
|
22
|
+
- @atlaspack/types-internal@2.20.3
|
|
23
|
+
|
|
24
|
+
## 2.14.11
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- Updated dependencies []:
|
|
29
|
+
- @atlaspack/types-internal@2.20.2
|
|
30
|
+
|
|
31
|
+
## 2.14.10
|
|
32
|
+
|
|
33
|
+
### Patch Changes
|
|
34
|
+
|
|
35
|
+
- [#785](https://github.com/atlassian-labs/atlaspack/pull/785) [`0e7dd5e`](https://github.com/atlassian-labs/atlaspack/commit/0e7dd5ec6fbe05aa9e0bb5775a9d0975f206a922) Thanks [@matt-koko](https://github.com/matt-koko)! - We need to re-publish every package in Atlaspack with the corrected types field.
|
|
36
|
+
|
|
37
|
+
- Updated dependencies [[`0e7dd5e`](https://github.com/atlassian-labs/atlaspack/commit/0e7dd5ec6fbe05aa9e0bb5775a9d0975f206a922)]:
|
|
38
|
+
- @atlaspack/types-internal@2.20.1
|
|
39
|
+
|
|
40
|
+
## 2.14.9
|
|
41
|
+
|
|
42
|
+
### Patch Changes
|
|
43
|
+
|
|
44
|
+
- Updated dependencies [[`eedcbc4`](https://github.com/atlassian-labs/atlaspack/commit/eedcbc408fc1e86a2a8e25f1a41c57146d8529e1), [`f6532d7`](https://github.com/atlassian-labs/atlaspack/commit/f6532d7a4f7f007bd4e5e36af04dd466f0b9f572)]:
|
|
45
|
+
- @atlaspack/types-internal@2.20.0
|
|
46
|
+
|
|
47
|
+
## 2.14.8
|
|
48
|
+
|
|
49
|
+
### Patch Changes
|
|
50
|
+
|
|
51
|
+
- Updated dependencies []:
|
|
52
|
+
- @atlaspack/types-internal@2.19.5
|
|
53
|
+
|
|
54
|
+
## 2.14.7
|
|
55
|
+
|
|
56
|
+
### Patch Changes
|
|
57
|
+
|
|
58
|
+
- Updated dependencies []:
|
|
59
|
+
- @atlaspack/types-internal@2.19.4
|
|
60
|
+
|
|
61
|
+
## 2.14.6
|
|
62
|
+
|
|
63
|
+
### Patch Changes
|
|
64
|
+
|
|
65
|
+
- Updated dependencies []:
|
|
66
|
+
- @atlaspack/types-internal@2.19.3
|
|
67
|
+
|
|
68
|
+
## 2.14.5
|
|
69
|
+
|
|
70
|
+
### Patch Changes
|
|
71
|
+
|
|
72
|
+
- [#742](https://github.com/atlassian-labs/atlaspack/pull/742) [`ee040bb`](https://github.com/atlassian-labs/atlaspack/commit/ee040bb6428f29b57d892ddd8107e29077d08ffd) Thanks [@yamadapc](https://github.com/yamadapc)! - Internal changes and bug fixes to environmentDeduplication flag
|
|
73
|
+
|
|
74
|
+
- Updated dependencies [[`ee040bb`](https://github.com/atlassian-labs/atlaspack/commit/ee040bb6428f29b57d892ddd8107e29077d08ffd)]:
|
|
75
|
+
- @atlaspack/types-internal@2.19.2
|
|
76
|
+
|
|
77
|
+
## 2.14.4
|
|
78
|
+
|
|
79
|
+
### Patch Changes
|
|
80
|
+
|
|
81
|
+
- Updated dependencies []:
|
|
82
|
+
- @atlaspack/types-internal@2.19.1
|
|
83
|
+
|
|
84
|
+
## 2.14.3
|
|
85
|
+
|
|
86
|
+
### Patch Changes
|
|
87
|
+
|
|
88
|
+
- Updated dependencies [[`7f5841c`](https://github.com/atlassian-labs/atlaspack/commit/7f5841c39df049f9546cccbeea2a7337e0337b45)]:
|
|
89
|
+
- @atlaspack/types-internal@2.19.0
|
|
90
|
+
|
|
91
|
+
## 2.14.2
|
|
92
|
+
|
|
93
|
+
### Patch Changes
|
|
94
|
+
|
|
95
|
+
- [#720](https://github.com/atlassian-labs/atlaspack/pull/720) [`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94) Thanks [@alshdavid](https://github.com/alshdavid)! - Migrate to TypeScript
|
|
96
|
+
|
|
3
97
|
## 2.14.1
|
|
4
98
|
|
|
5
99
|
### Patch Changes
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CompilerHost = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const FSHost_1 = require("./FSHost");
|
|
9
|
+
class CompilerHost extends FSHost_1.FSHost {
|
|
10
|
+
// @ts-expect-error Cannot use namespace 'TypeScriptModule' as a type.
|
|
11
|
+
constructor(fs, ts, logger) {
|
|
12
|
+
super(fs, ts);
|
|
13
|
+
// workaround for https://github.com/microsoft/TypeScript/issues/39547
|
|
14
|
+
this.redirectTypes = new Map();
|
|
15
|
+
this.logger = logger;
|
|
16
|
+
}
|
|
17
|
+
readFile(filePath) {
|
|
18
|
+
let contents = super.readFile(filePath);
|
|
19
|
+
if (contents && path_1.default.basename(filePath) === 'package.json') {
|
|
20
|
+
let json = JSON.parse(contents);
|
|
21
|
+
if (json.types != null &&
|
|
22
|
+
json.source != null &&
|
|
23
|
+
!super.fileExists(path_1.default.posix.join(path_1.default.posix.dirname(filePath), json.types))) {
|
|
24
|
+
let source = path_1.default.posix.join(path_1.default.posix.dirname(filePath),
|
|
25
|
+
// @ts-expect-error Argument of type 'string | string[]' is not assignable to parameter of type 'string'.
|
|
26
|
+
json.source);
|
|
27
|
+
let fakeTypes = source.slice(0, -path_1.default.posix.extname(source).length) + '.d.ts';
|
|
28
|
+
this.redirectTypes.set(fakeTypes, source);
|
|
29
|
+
json.types = fakeTypes;
|
|
30
|
+
this.logger.verbose({
|
|
31
|
+
message: `Faking missing \`types\` field in ${filePath} to be ${source}`,
|
|
32
|
+
});
|
|
33
|
+
return JSON.stringify(json);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return contents;
|
|
37
|
+
}
|
|
38
|
+
fileExists(filePath) {
|
|
39
|
+
if (this.redirectTypes.has(filePath)) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return super.fileExists(filePath);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
getSourceFile(filePath, languageVersion) {
|
|
47
|
+
let redirect = this.redirectTypes.get(filePath);
|
|
48
|
+
if (redirect != null) {
|
|
49
|
+
const sourceText = this.readFile(redirect);
|
|
50
|
+
return sourceText !== undefined
|
|
51
|
+
? this.ts.createSourceFile(filePath, sourceText, languageVersion)
|
|
52
|
+
: undefined;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
const sourceText = this.readFile(filePath);
|
|
56
|
+
return sourceText !== undefined
|
|
57
|
+
? this.ts.createSourceFile(filePath, sourceText, languageVersion)
|
|
58
|
+
: undefined;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
getDefaultLibFileName(options) {
|
|
62
|
+
return this.ts.getDefaultLibFilePath(options);
|
|
63
|
+
}
|
|
64
|
+
writeFile(filePath, content) {
|
|
65
|
+
if (path_1.default.extname(filePath) === '.map') {
|
|
66
|
+
this.outputMap = content;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
this.outputCode = content;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
getCanonicalFileName(fileName) {
|
|
73
|
+
return this.ts.sys.useCaseSensitiveFileNames
|
|
74
|
+
? fileName
|
|
75
|
+
: fileName.toLowerCase();
|
|
76
|
+
}
|
|
77
|
+
useCaseSensitiveFileNames() {
|
|
78
|
+
return this.ts.sys.useCaseSensitiveFileNames;
|
|
79
|
+
}
|
|
80
|
+
getNewLine() {
|
|
81
|
+
return this.ts.sys.newLine;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.CompilerHost = CompilerHost;
|
package/dist/FSHost.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.FSHost = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
class FSHost {
|
|
9
|
+
// @ts-expect-error Cannot use namespace 'TypeScriptModule' as a type.
|
|
10
|
+
constructor(fs, ts) {
|
|
11
|
+
this.getCurrentDirectory = () => {
|
|
12
|
+
return this.fs.cwd();
|
|
13
|
+
};
|
|
14
|
+
this.fs = fs;
|
|
15
|
+
this.ts = ts;
|
|
16
|
+
}
|
|
17
|
+
fileExists(filePath) {
|
|
18
|
+
try {
|
|
19
|
+
return this.fs.statSync(filePath).isFile();
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
readFile(filePath) {
|
|
26
|
+
try {
|
|
27
|
+
return this.fs.readFileSync(filePath, 'utf8');
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
if (err.code === 'ENOENT') {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
throw err;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
directoryExists(filePath) {
|
|
37
|
+
try {
|
|
38
|
+
return this.fs.statSync(filePath).isDirectory();
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
realpath(filePath) {
|
|
45
|
+
try {
|
|
46
|
+
return this.fs.realpathSync(filePath);
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
return filePath;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
getAccessibleFileSystemEntries(dirPath) {
|
|
53
|
+
try {
|
|
54
|
+
let entries = this.fs.readdirSync(dirPath || '.').sort();
|
|
55
|
+
let files = [];
|
|
56
|
+
let directories = [];
|
|
57
|
+
for (let entry of entries) {
|
|
58
|
+
let filePath = path_1.default.join(dirPath, entry);
|
|
59
|
+
let stat;
|
|
60
|
+
try {
|
|
61
|
+
stat = this.fs.statSync(filePath);
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (stat.isFile()) {
|
|
67
|
+
files.push(entry);
|
|
68
|
+
}
|
|
69
|
+
else if (stat.isDirectory()) {
|
|
70
|
+
directories.push(entry);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return { files, directories };
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
return { files: [], directories: [] };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
readDirectory(root, extensions, excludes, includes, depth) {
|
|
80
|
+
return this.ts.matchFiles(root, extensions, excludes, includes, this.ts.sys.useCaseSensitiveFileNames, this.getCurrentDirectory(), depth, (dirPath) => this.getAccessibleFileSystemEntries(dirPath), (filePath) => this.realpath(filePath), (dirPath) => this.directoryExists(dirPath));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.FSHost = FSHost;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LanguageServiceHost = void 0;
|
|
4
|
+
const FSHost_1 = require("./FSHost");
|
|
5
|
+
// the typings from flow-typed define the ILanguageServiceHost interface as
|
|
6
|
+
// having its methods as properties with arrow functions. These should probably
|
|
7
|
+
// be methods instead.
|
|
8
|
+
class LanguageServiceHost extends FSHost_1.FSHost {
|
|
9
|
+
// @ts-expect-error Cannot use namespace 'TypeScriptModule' as a type.
|
|
10
|
+
constructor(fs, ts, config) {
|
|
11
|
+
super(fs, ts);
|
|
12
|
+
this.config = config;
|
|
13
|
+
this.files = {};
|
|
14
|
+
}
|
|
15
|
+
invalidate(fileName) {
|
|
16
|
+
// When the typescript language server calls "getScriptVersion", it will normalize paths for cross-platform (e.g. C:\myFile.ts on Windows becomes C:/myFile.ts). We need to do the same thing.
|
|
17
|
+
const normalizedFileName = this.ts.getNormalizedAbsolutePath(fileName);
|
|
18
|
+
const entry = this.files[normalizedFileName];
|
|
19
|
+
if (entry) {
|
|
20
|
+
entry.version++;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
this.files[normalizedFileName] = {
|
|
24
|
+
version: 0,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
getScriptFileNames() {
|
|
29
|
+
return this.config.fileNames;
|
|
30
|
+
}
|
|
31
|
+
getScriptVersion(fileName) {
|
|
32
|
+
// @ts-expect-error string | undefined
|
|
33
|
+
return this.files[fileName] && this.files[fileName].version.toString();
|
|
34
|
+
}
|
|
35
|
+
getScriptSnapshot(fileName) {
|
|
36
|
+
if (!this.fileExists(fileName)) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const content = this.readFile(fileName);
|
|
40
|
+
if (content) {
|
|
41
|
+
return this.ts.ScriptSnapshot.fromString(content);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
getCompilationSettings() {
|
|
45
|
+
return this.config.options;
|
|
46
|
+
}
|
|
47
|
+
getDefaultLibFileName(projectOptions) {
|
|
48
|
+
return this.ts.getDefaultLibFilePath(projectOptions);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.LanguageServiceHost = LanguageServiceHost;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ParseConfigHost = void 0;
|
|
4
|
+
const FSHost_1 = require("./FSHost");
|
|
5
|
+
class ParseConfigHost extends FSHost_1.FSHost {
|
|
6
|
+
// @ts-expect-error Cannot use namespace 'TypeScriptModule' as a type.
|
|
7
|
+
constructor(fs, ts) {
|
|
8
|
+
super(fs, ts);
|
|
9
|
+
this.filesRead = new Set();
|
|
10
|
+
this.useCaseSensitiveFileNames = ts.sys.useCaseSensitiveFileNames;
|
|
11
|
+
}
|
|
12
|
+
readFile(filePath) {
|
|
13
|
+
this.filesRead.add(filePath);
|
|
14
|
+
return super.readFile(filePath);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.ParseConfigHost = ParseConfigHost;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadTSConfig = exports.LanguageServiceHost = exports.ParseConfigHost = exports.CompilerHost = exports.FSHost = void 0;
|
|
4
|
+
var FSHost_1 = require("./FSHost");
|
|
5
|
+
Object.defineProperty(exports, "FSHost", { enumerable: true, get: function () { return FSHost_1.FSHost; } });
|
|
6
|
+
var CompilerHost_1 = require("./CompilerHost");
|
|
7
|
+
Object.defineProperty(exports, "CompilerHost", { enumerable: true, get: function () { return CompilerHost_1.CompilerHost; } });
|
|
8
|
+
var ParseConfigHost_1 = require("./ParseConfigHost");
|
|
9
|
+
Object.defineProperty(exports, "ParseConfigHost", { enumerable: true, get: function () { return ParseConfigHost_1.ParseConfigHost; } });
|
|
10
|
+
var LanguageServiceHost_1 = require("./LanguageServiceHost");
|
|
11
|
+
Object.defineProperty(exports, "LanguageServiceHost", { enumerable: true, get: function () { return LanguageServiceHost_1.LanguageServiceHost; } });
|
|
12
|
+
var loadTSConfig_1 = require("./loadTSConfig");
|
|
13
|
+
Object.defineProperty(exports, "loadTSConfig", { enumerable: true, get: function () { return loadTSConfig_1.loadTSConfig; } });
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.loadTSConfig = loadTSConfig;
|
|
7
|
+
const ParseConfigHost_1 = require("./ParseConfigHost");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const nullthrows_1 = __importDefault(require("nullthrows"));
|
|
10
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
11
|
+
async function loadTSConfig(config, options) {
|
|
12
|
+
let configResult = await config.getConfig(['tsconfig.json']);
|
|
13
|
+
if (!configResult) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
let host = new ParseConfigHost_1.ParseConfigHost(options.inputFS, typescript_1.default);
|
|
17
|
+
let parsedConfig = typescript_1.default.parseJsonConfigFileContent(configResult.contents, host, path_1.default.dirname((0, nullthrows_1.default)(configResult.filePath)));
|
|
18
|
+
// Add all of the extended config files to be watched
|
|
19
|
+
for (let file of host.filesRead) {
|
|
20
|
+
config.invalidateOnFileChange(path_1.default.resolve(file));
|
|
21
|
+
}
|
|
22
|
+
return parsedConfig.options;
|
|
23
|
+
}
|
package/lib/CompilerHost.js
CHANGED
|
@@ -14,10 +14,14 @@ function _path() {
|
|
|
14
14
|
var _FSHost = require("./FSHost");
|
|
15
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
16
|
// eslint-disable-line import/no-extraneous-dependencies
|
|
17
|
+
|
|
17
18
|
// eslint-disable-line import/no-extraneous-dependencies
|
|
19
|
+
|
|
18
20
|
class CompilerHost extends _FSHost.FSHost {
|
|
19
21
|
// workaround for https://github.com/microsoft/TypeScript/issues/39547
|
|
20
22
|
redirectTypes = new Map();
|
|
23
|
+
|
|
24
|
+
// @ts-expect-error Cannot use namespace 'TypeScriptModule' as a type.
|
|
21
25
|
constructor(fs, ts, logger) {
|
|
22
26
|
super(fs, ts);
|
|
23
27
|
this.logger = logger;
|
|
@@ -27,7 +31,9 @@ class CompilerHost extends _FSHost.FSHost {
|
|
|
27
31
|
if (contents && _path().default.basename(filePath) === 'package.json') {
|
|
28
32
|
let json = JSON.parse(contents);
|
|
29
33
|
if (json.types != null && json.source != null && !super.fileExists(_path().default.posix.join(_path().default.posix.dirname(filePath), json.types))) {
|
|
30
|
-
let source = _path().default.posix.join(_path().default.posix.dirname(filePath),
|
|
34
|
+
let source = _path().default.posix.join(_path().default.posix.dirname(filePath),
|
|
35
|
+
// @ts-expect-error Argument of type 'string | string[]' is not assignable to parameter of type 'string'.
|
|
36
|
+
json.source);
|
|
31
37
|
let fakeTypes = source.slice(0, -_path().default.posix.extname(source).length) + '.d.ts';
|
|
32
38
|
this.redirectTypes.set(fakeTypes, source);
|
|
33
39
|
json.types = fakeTypes;
|
package/lib/FSHost.js
CHANGED
|
@@ -13,7 +13,11 @@ function _path() {
|
|
|
13
13
|
}
|
|
14
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
15
|
// eslint-disable-line import/no-extraneous-dependencies
|
|
16
|
+
|
|
16
17
|
class FSHost {
|
|
18
|
+
// @ts-expect-error Cannot use namespace 'TypeScriptModule' as a type.
|
|
19
|
+
|
|
20
|
+
// @ts-expect-error Cannot use namespace 'TypeScriptModule' as a type.
|
|
17
21
|
constructor(fs, ts) {
|
|
18
22
|
this.fs = fs;
|
|
19
23
|
this.ts = ts;
|
|
@@ -83,7 +87,6 @@ class FSHost {
|
|
|
83
87
|
}
|
|
84
88
|
}
|
|
85
89
|
readDirectory(root, extensions, excludes, includes, depth) {
|
|
86
|
-
// $FlowFixMe[prop-missing]
|
|
87
90
|
return this.ts.matchFiles(root, extensions, excludes, includes, this.ts.sys.useCaseSensitiveFileNames, this.getCurrentDirectory(), depth, dirPath => this.getAccessibleFileSystemEntries(dirPath), filePath => this.realpath(filePath), dirPath => this.directoryExists(dirPath));
|
|
88
91
|
}
|
|
89
92
|
}
|
|
@@ -6,11 +6,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.LanguageServiceHost = void 0;
|
|
7
7
|
var _FSHost = require("./FSHost");
|
|
8
8
|
// eslint-disable-line import/no-extraneous-dependencies
|
|
9
|
+
|
|
9
10
|
// the typings from flow-typed define the ILanguageServiceHost interface as
|
|
10
11
|
// having its methods as properties with arrow functions. These should probably
|
|
11
12
|
// be methods instead.
|
|
12
|
-
// $FlowFixMe[method-unbinding]
|
|
13
13
|
class LanguageServiceHost extends _FSHost.FSHost {
|
|
14
|
+
// @ts-expect-error Cannot use namespace 'TypeScriptModule' as a type.
|
|
14
15
|
constructor(fs, ts, config) {
|
|
15
16
|
super(fs, ts);
|
|
16
17
|
this.config = config;
|
|
@@ -18,7 +19,6 @@ class LanguageServiceHost extends _FSHost.FSHost {
|
|
|
18
19
|
}
|
|
19
20
|
invalidate(fileName) {
|
|
20
21
|
// When the typescript language server calls "getScriptVersion", it will normalize paths for cross-platform (e.g. C:\myFile.ts on Windows becomes C:/myFile.ts). We need to do the same thing.
|
|
21
|
-
// $FlowFixMe getNormalizedAbsolutePath is missing from the flow-typed definition.
|
|
22
22
|
const normalizedFileName = this.ts.getNormalizedAbsolutePath(fileName);
|
|
23
23
|
const entry = this.files[normalizedFileName];
|
|
24
24
|
if (entry) {
|
|
@@ -33,6 +33,7 @@ class LanguageServiceHost extends _FSHost.FSHost {
|
|
|
33
33
|
return this.config.fileNames;
|
|
34
34
|
}
|
|
35
35
|
getScriptVersion(fileName) {
|
|
36
|
+
// @ts-expect-error string | undefined
|
|
36
37
|
return this.files[fileName] && this.files[fileName].version.toString();
|
|
37
38
|
}
|
|
38
39
|
getScriptSnapshot(fileName) {
|
|
@@ -41,7 +42,6 @@ class LanguageServiceHost extends _FSHost.FSHost {
|
|
|
41
42
|
}
|
|
42
43
|
const content = this.readFile(fileName);
|
|
43
44
|
if (content) {
|
|
44
|
-
// $FlowFixMe
|
|
45
45
|
return this.ts.ScriptSnapshot.fromString(content);
|
|
46
46
|
}
|
|
47
47
|
}
|
package/lib/ParseConfigHost.js
CHANGED
|
@@ -7,7 +7,9 @@ exports.ParseConfigHost = void 0;
|
|
|
7
7
|
var _FSHost = require("./FSHost");
|
|
8
8
|
// eslint-disable-line import/no-extraneous-dependencies
|
|
9
9
|
// eslint-disable-line import/no-extraneous-dependencies
|
|
10
|
+
|
|
10
11
|
class ParseConfigHost extends _FSHost.FSHost {
|
|
12
|
+
// @ts-expect-error Cannot use namespace 'TypeScriptModule' as a type.
|
|
11
13
|
constructor(fs, ts) {
|
|
12
14
|
super(fs, ts);
|
|
13
15
|
this.filesRead = new Set();
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { FilePath, FileSystem, PluginLogger } from '@atlaspack/types-internal';
|
|
2
|
+
import type { CompilerOptions, SourceFile } from 'typescript';
|
|
3
|
+
import { ScriptTarget } from 'typescript';
|
|
4
|
+
import { FSHost } from './FSHost';
|
|
5
|
+
export declare class CompilerHost extends FSHost {
|
|
6
|
+
outputCode: string | null | undefined;
|
|
7
|
+
outputMap: string | null | undefined;
|
|
8
|
+
logger: PluginLogger;
|
|
9
|
+
redirectTypes: Map<FilePath, FilePath>;
|
|
10
|
+
constructor(fs: FileSystem, ts: TypeScriptModule, logger: PluginLogger);
|
|
11
|
+
readFile(filePath: FilePath): undefined | string;
|
|
12
|
+
fileExists(filePath: FilePath): boolean;
|
|
13
|
+
getSourceFile(filePath: FilePath, languageVersion: ScriptTarget[keyof ScriptTarget]): undefined | SourceFile;
|
|
14
|
+
getDefaultLibFileName(options: CompilerOptions): string;
|
|
15
|
+
writeFile(filePath: FilePath, content: string): void;
|
|
16
|
+
getCanonicalFileName(fileName: FilePath): FilePath;
|
|
17
|
+
useCaseSensitiveFileNames(): boolean;
|
|
18
|
+
getNewLine(): string;
|
|
19
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { FileSystem, FilePath } from '@atlaspack/types-internal';
|
|
2
|
+
export declare class FSHost {
|
|
3
|
+
fs: FileSystem;
|
|
4
|
+
ts: TypeScriptModule;
|
|
5
|
+
constructor(fs: FileSystem, ts: TypeScriptModule);
|
|
6
|
+
getCurrentDirectory: () => FilePath;
|
|
7
|
+
fileExists(filePath: FilePath): boolean;
|
|
8
|
+
readFile(filePath: FilePath): undefined | string;
|
|
9
|
+
directoryExists(filePath: FilePath): boolean;
|
|
10
|
+
realpath(filePath: FilePath): FilePath;
|
|
11
|
+
getAccessibleFileSystemEntries(dirPath: FilePath): {
|
|
12
|
+
directories: Array<FilePath>;
|
|
13
|
+
files: Array<FilePath>;
|
|
14
|
+
};
|
|
15
|
+
readDirectory(root: FilePath, extensions?: ReadonlyArray<string>, excludes?: ReadonlyArray<string>, includes?: ReadonlyArray<string>, depth?: number): any;
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { FileSystem, FilePath } from '@atlaspack/types-internal';
|
|
2
|
+
import type { CompilerOptions, LanguageServiceHost as ILanguageServiceHost, IScriptSnapshot, ParsedCommandLine } from 'typescript';
|
|
3
|
+
import { FSHost } from './FSHost';
|
|
4
|
+
export declare class LanguageServiceHost extends FSHost implements ILanguageServiceHost {
|
|
5
|
+
config: ParsedCommandLine;
|
|
6
|
+
files: Partial<Record<FilePath, {
|
|
7
|
+
version: number;
|
|
8
|
+
}>>;
|
|
9
|
+
constructor(fs: FileSystem, ts: TypeScriptModule, config: ParsedCommandLine);
|
|
10
|
+
invalidate(fileName: FilePath): void;
|
|
11
|
+
getScriptFileNames(): Array<string>;
|
|
12
|
+
getScriptVersion(fileName: FilePath): string;
|
|
13
|
+
getScriptSnapshot(fileName: string): IScriptSnapshot | undefined;
|
|
14
|
+
getCompilationSettings(): CompilerOptions;
|
|
15
|
+
getDefaultLibFileName(projectOptions: any): string;
|
|
16
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { FileSystem, FilePath } from '@atlaspack/types-internal';
|
|
2
|
+
import type { ParseConfigHost as IParseConfigHost } from 'typescript';
|
|
3
|
+
import { FSHost } from './FSHost';
|
|
4
|
+
export declare class ParseConfigHost extends FSHost implements IParseConfigHost {
|
|
5
|
+
filesRead: Set<FilePath>;
|
|
6
|
+
useCaseSensitiveFileNames: boolean;
|
|
7
|
+
constructor(fs: FileSystem, ts: TypeScriptModule);
|
|
8
|
+
readFile(filePath: FilePath): undefined | string;
|
|
9
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/ts-utils",
|
|
3
|
-
"version": "2.14.1-canary.
|
|
3
|
+
"version": "2.14.1-canary.320+01868d011",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -9,12 +9,14 @@
|
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "https://github.com/atlassian-labs/atlaspack.git"
|
|
11
11
|
},
|
|
12
|
-
"main": "lib/index.js",
|
|
13
|
-
"source": "src/index.
|
|
12
|
+
"main": "./lib/index.js",
|
|
13
|
+
"source": "./src/index.ts",
|
|
14
|
+
"types": "./lib/types/index.d.ts",
|
|
14
15
|
"engines": {
|
|
15
16
|
"node": ">= 16.0.0"
|
|
16
17
|
},
|
|
17
18
|
"dependencies": {
|
|
19
|
+
"@atlaspack/types-internal": "2.14.1-canary.320+01868d011",
|
|
18
20
|
"nullthrows": "^1.1.1"
|
|
19
21
|
},
|
|
20
22
|
"devDependencies": {
|
|
@@ -24,5 +26,8 @@
|
|
|
24
26
|
"typescript": ">=3.0.0"
|
|
25
27
|
},
|
|
26
28
|
"type": "commonjs",
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build:lib": "gulp build --gulpfile ../../../gulpfile.js --cwd ."
|
|
31
|
+
},
|
|
32
|
+
"gitHead": "01868d0116693b7e80b5f7d3ba9fd3d21934525c"
|
|
33
|
+
}
|
|
@@ -1,26 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type {
|
|
2
|
+
FilePath,
|
|
3
|
+
FileSystem,
|
|
4
|
+
PackageJSON,
|
|
5
|
+
PluginLogger,
|
|
6
|
+
} from '@atlaspack/types-internal';
|
|
7
|
+
import TypeScriptModule from 'typescript'; // eslint-disable-line import/no-extraneous-dependencies
|
|
5
8
|
import type {CompilerOptions, SourceFile} from 'typescript';
|
|
6
|
-
import
|
|
9
|
+
import {ScriptTarget} from 'typescript'; // eslint-disable-line import/no-extraneous-dependencies
|
|
7
10
|
|
|
8
11
|
import path from 'path';
|
|
9
12
|
import {FSHost} from './FSHost';
|
|
10
13
|
|
|
11
14
|
export class CompilerHost extends FSHost {
|
|
12
|
-
outputCode:
|
|
13
|
-
outputMap:
|
|
15
|
+
outputCode: string | null | undefined;
|
|
16
|
+
outputMap: string | null | undefined;
|
|
14
17
|
logger: PluginLogger;
|
|
15
18
|
// workaround for https://github.com/microsoft/TypeScript/issues/39547
|
|
16
19
|
redirectTypes: Map<FilePath, FilePath> = new Map();
|
|
17
20
|
|
|
21
|
+
// @ts-expect-error Cannot use namespace 'TypeScriptModule' as a type.
|
|
18
22
|
constructor(fs: FileSystem, ts: TypeScriptModule, logger: PluginLogger) {
|
|
19
23
|
super(fs, ts);
|
|
20
24
|
this.logger = logger;
|
|
21
25
|
}
|
|
22
26
|
|
|
23
|
-
readFile(filePath: FilePath):
|
|
27
|
+
readFile(filePath: FilePath): undefined | string {
|
|
24
28
|
let contents = super.readFile(filePath);
|
|
25
29
|
if (contents && path.basename(filePath) === 'package.json') {
|
|
26
30
|
let json: PackageJSON = JSON.parse(contents);
|
|
@@ -31,7 +35,11 @@ export class CompilerHost extends FSHost {
|
|
|
31
35
|
path.posix.join(path.posix.dirname(filePath), json.types),
|
|
32
36
|
)
|
|
33
37
|
) {
|
|
34
|
-
let source = path.posix.join(
|
|
38
|
+
let source = path.posix.join(
|
|
39
|
+
path.posix.dirname(filePath),
|
|
40
|
+
// @ts-expect-error Argument of type 'string | string[]' is not assignable to parameter of type 'string'.
|
|
41
|
+
json.source,
|
|
42
|
+
);
|
|
35
43
|
let fakeTypes =
|
|
36
44
|
source.slice(0, -path.posix.extname(source).length) + '.d.ts';
|
|
37
45
|
this.redirectTypes.set(fakeTypes, source);
|
|
@@ -55,8 +63,8 @@ export class CompilerHost extends FSHost {
|
|
|
55
63
|
|
|
56
64
|
getSourceFile(
|
|
57
65
|
filePath: FilePath,
|
|
58
|
-
languageVersion:
|
|
59
|
-
):
|
|
66
|
+
languageVersion: ScriptTarget[keyof ScriptTarget],
|
|
67
|
+
): undefined | SourceFile {
|
|
60
68
|
let redirect = this.redirectTypes.get(filePath);
|
|
61
69
|
if (redirect != null) {
|
|
62
70
|
const sourceText = this.readFile(redirect);
|