@atlaspack/ts-utils 2.14.2-typescript-6de04fbae.0 → 2.14.2-typescript-08dcc1c9b.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.
@@ -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), json.source);
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
  }
@@ -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();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/ts-utils",
3
- "version": "2.14.2-typescript-6de04fbae.0",
3
+ "version": "2.14.2-typescript-08dcc1c9b.0",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -10,7 +10,7 @@
10
10
  "url": "https://github.com/atlassian-labs/atlaspack.git"
11
11
  },
12
12
  "main": "lib/index.js",
13
- "source": "src/index.js",
13
+ "source": "src/index.ts",
14
14
  "engines": {
15
15
  "node": ">= 16.0.0"
16
16
  },
@@ -24,5 +24,9 @@
24
24
  "typescript": ">=3.0.0"
25
25
  },
26
26
  "type": "commonjs",
27
- "gitHead": "6de04fbaeccfba1e7832c737f6318cbd603fc74d"
27
+ "scripts": {
28
+ "check-ts": "tsc --noEmit"
29
+ },
30
+ "types": "src/index.ts",
31
+ "gitHead": "08dcc1c9bcdc6ab931d55e05ccc0f45669de2f22"
28
32
  }
@@ -1,26 +1,26 @@
1
- // @flow
2
1
  import type {FileSystem} from '@atlaspack/fs';
3
2
  import type {FilePath, PackageJSON, PluginLogger} from '@atlaspack/types';
4
- import typeof TypeScriptModule from 'typescript'; // eslint-disable-line import/no-extraneous-dependencies
3
+ import TypeScriptModule from 'typescript'; // eslint-disable-line import/no-extraneous-dependencies
5
4
  import type {CompilerOptions, SourceFile} from 'typescript';
6
- import typeof {ScriptTarget} from 'typescript'; // eslint-disable-line import/no-extraneous-dependencies
5
+ import {ScriptTarget} from 'typescript'; // eslint-disable-line import/no-extraneous-dependencies
7
6
 
8
7
  import path from 'path';
9
8
  import {FSHost} from './FSHost';
10
9
 
11
10
  export class CompilerHost extends FSHost {
12
- outputCode: ?string;
13
- outputMap: ?string;
11
+ outputCode: string | null | undefined;
12
+ outputMap: string | null | undefined;
14
13
  logger: PluginLogger;
15
14
  // workaround for https://github.com/microsoft/TypeScript/issues/39547
16
15
  redirectTypes: Map<FilePath, FilePath> = new Map();
17
16
 
17
+ // @ts-expect-error Cannot use namespace 'TypeScriptModule' as a type.
18
18
  constructor(fs: FileSystem, ts: TypeScriptModule, logger: PluginLogger) {
19
19
  super(fs, ts);
20
20
  this.logger = logger;
21
21
  }
22
22
 
23
- readFile(filePath: FilePath): void | string {
23
+ readFile(filePath: FilePath): undefined | string {
24
24
  let contents = super.readFile(filePath);
25
25
  if (contents && path.basename(filePath) === 'package.json') {
26
26
  let json: PackageJSON = JSON.parse(contents);
@@ -31,7 +31,11 @@ export class CompilerHost extends FSHost {
31
31
  path.posix.join(path.posix.dirname(filePath), json.types),
32
32
  )
33
33
  ) {
34
- let source = path.posix.join(path.posix.dirname(filePath), json.source);
34
+ let source = path.posix.join(
35
+ path.posix.dirname(filePath),
36
+ // @ts-expect-error Argument of type 'string | string[]' is not assignable to parameter of type 'string'.
37
+ json.source,
38
+ );
35
39
  let fakeTypes =
36
40
  source.slice(0, -path.posix.extname(source).length) + '.d.ts';
37
41
  this.redirectTypes.set(fakeTypes, source);
@@ -55,8 +59,8 @@ export class CompilerHost extends FSHost {
55
59
 
56
60
  getSourceFile(
57
61
  filePath: FilePath,
58
- languageVersion: $Values<ScriptTarget>,
59
- ): void | SourceFile {
62
+ languageVersion: ScriptTarget[keyof ScriptTarget],
63
+ ): undefined | SourceFile {
60
64
  let redirect = this.redirectTypes.get(filePath);
61
65
  if (redirect != null) {
62
66
  const sourceText = this.readFile(redirect);
@@ -1,13 +1,14 @@
1
- // @flow
2
1
  import type {FileSystem} from '@atlaspack/fs';
3
2
  import type {FilePath} from '@atlaspack/types';
4
- import typeof TypeScriptModule from 'typescript'; // eslint-disable-line import/no-extraneous-dependencies
3
+ import TypeScriptModule from 'typescript'; // eslint-disable-line import/no-extraneous-dependencies
5
4
  import path from 'path';
6
5
 
7
6
  export class FSHost {
8
7
  fs: FileSystem;
8
+ // @ts-expect-error Cannot use namespace 'TypeScriptModule' as a type.
9
9
  ts: TypeScriptModule;
10
10
 
11
+ // @ts-expect-error Cannot use namespace 'TypeScriptModule' as a type.
11
12
  constructor(fs: FileSystem, ts: TypeScriptModule) {
12
13
  this.fs = fs;
13
14
  this.ts = ts;
@@ -20,15 +21,15 @@ export class FSHost {
20
21
  fileExists(filePath: FilePath): boolean {
21
22
  try {
22
23
  return this.fs.statSync(filePath).isFile();
23
- } catch (err) {
24
+ } catch (err: any) {
24
25
  return false;
25
26
  }
26
27
  }
27
28
 
28
- readFile(filePath: FilePath): void | string {
29
+ readFile(filePath: FilePath): undefined | string {
29
30
  try {
30
31
  return this.fs.readFileSync(filePath, 'utf8');
31
- } catch (err) {
32
+ } catch (err: any) {
32
33
  if (err.code === 'ENOENT') {
33
34
  return undefined;
34
35
  }
@@ -40,7 +41,7 @@ export class FSHost {
40
41
  directoryExists(filePath: FilePath): boolean {
41
42
  try {
42
43
  return this.fs.statSync(filePath).isDirectory();
43
- } catch (err) {
44
+ } catch (err: any) {
44
45
  return false;
45
46
  }
46
47
  }
@@ -48,26 +49,26 @@ export class FSHost {
48
49
  realpath(filePath: FilePath): FilePath {
49
50
  try {
50
51
  return this.fs.realpathSync(filePath);
51
- } catch (err) {
52
+ } catch (err: any) {
52
53
  return filePath;
53
54
  }
54
55
  }
55
56
 
56
- getAccessibleFileSystemEntries(dirPath: FilePath): {|
57
- directories: Array<FilePath>,
58
- files: Array<FilePath>,
59
- |} {
57
+ getAccessibleFileSystemEntries(dirPath: FilePath): {
58
+ directories: Array<FilePath>;
59
+ files: Array<FilePath>;
60
+ } {
60
61
  try {
61
62
  let entries = this.fs.readdirSync(dirPath || '.').sort();
62
- let files = [];
63
- let directories = [];
63
+ let files: Array<FilePath> = [];
64
+ let directories: Array<FilePath> = [];
64
65
  for (let entry of entries) {
65
66
  let filePath = path.join(dirPath, entry);
66
67
 
67
68
  let stat;
68
69
  try {
69
70
  stat = this.fs.statSync(filePath);
70
- } catch (e) {
71
+ } catch (e: any) {
71
72
  continue;
72
73
  }
73
74
 
@@ -79,19 +80,18 @@ export class FSHost {
79
80
  }
80
81
 
81
82
  return {files, directories};
82
- } catch (err) {
83
+ } catch (err: any) {
83
84
  return {files: [], directories: []};
84
85
  }
85
86
  }
86
87
 
87
88
  readDirectory(
88
89
  root: FilePath,
89
- extensions?: $ReadOnlyArray<string>,
90
- excludes?: $ReadOnlyArray<string>,
91
- includes?: $ReadOnlyArray<string>,
90
+ extensions?: ReadonlyArray<string>,
91
+ excludes?: ReadonlyArray<string>,
92
+ includes?: ReadonlyArray<string>,
92
93
  depth?: number,
93
94
  ): any {
94
- // $FlowFixMe[prop-missing]
95
95
  return this.ts.matchFiles(
96
96
  root,
97
97
  extensions,
@@ -100,9 +100,9 @@ export class FSHost {
100
100
  this.ts.sys.useCaseSensitiveFileNames,
101
101
  this.getCurrentDirectory(),
102
102
  depth,
103
- (dirPath) => this.getAccessibleFileSystemEntries(dirPath),
104
- (filePath) => this.realpath(filePath),
105
- (dirPath) => this.directoryExists(dirPath),
103
+ (dirPath: any) => this.getAccessibleFileSystemEntries(dirPath),
104
+ (filePath: any) => this.realpath(filePath),
105
+ (dirPath: any) => this.directoryExists(dirPath),
106
106
  );
107
107
  }
108
108
  }
@@ -1,7 +1,6 @@
1
- // @flow
2
1
  import type {FileSystem} from '@atlaspack/fs';
3
2
  import type {FilePath} from '@atlaspack/types';
4
- import typeof TypeScriptModule from 'typescript'; // eslint-disable-line import/no-extraneous-dependencies
3
+ import TypeScriptModule from 'typescript'; // eslint-disable-line import/no-extraneous-dependencies
5
4
  import type {
6
5
  CompilerOptions,
7
6
  LanguageServiceHost as ILanguageServiceHost,
@@ -13,14 +12,21 @@ import {FSHost} from './FSHost';
13
12
  // the typings from flow-typed define the ILanguageServiceHost interface as
14
13
  // having its methods as properties with arrow functions. These should probably
15
14
  // be methods instead.
16
- // $FlowFixMe[method-unbinding]
17
15
  export class LanguageServiceHost
18
16
  extends FSHost
19
17
  implements ILanguageServiceHost
20
18
  {
21
19
  config: ParsedCommandLine;
22
- files: {|[key: FilePath]: {|version: number|}|};
20
+ files: Partial<
21
+ Record<
22
+ FilePath,
23
+ {
24
+ version: number;
25
+ }
26
+ >
27
+ >;
23
28
 
29
+ // @ts-expect-error Cannot use namespace 'TypeScriptModule' as a type.
24
30
  constructor(fs: FileSystem, ts: TypeScriptModule, config: ParsedCommandLine) {
25
31
  super(fs, ts);
26
32
  this.config = config;
@@ -29,7 +35,6 @@ export class LanguageServiceHost
29
35
 
30
36
  invalidate(fileName: FilePath) {
31
37
  // 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.
32
- // $FlowFixMe getNormalizedAbsolutePath is missing from the flow-typed definition.
33
38
  const normalizedFileName = this.ts.getNormalizedAbsolutePath(fileName);
34
39
  const entry = this.files[normalizedFileName];
35
40
 
@@ -47,10 +52,11 @@ export class LanguageServiceHost
47
52
  }
48
53
 
49
54
  getScriptVersion(fileName: FilePath): string {
55
+ // @ts-expect-error string | undefined
50
56
  return this.files[fileName] && this.files[fileName].version.toString();
51
57
  }
52
58
 
53
- getScriptSnapshot(fileName: string): IScriptSnapshot | void {
59
+ getScriptSnapshot(fileName: string): IScriptSnapshot | undefined {
54
60
  if (!this.fileExists(fileName)) {
55
61
  return;
56
62
  }
@@ -58,7 +64,6 @@ export class LanguageServiceHost
58
64
  const content = this.readFile(fileName);
59
65
 
60
66
  if (content) {
61
- // $FlowFixMe
62
67
  return this.ts.ScriptSnapshot.fromString(content);
63
68
  }
64
69
  }
@@ -1,7 +1,6 @@
1
- // @flow
2
1
  import type {FileSystem} from '@atlaspack/fs';
3
2
  import type {FilePath} from '@atlaspack/types';
4
- import typeof TypeScriptModule from 'typescript'; // eslint-disable-line import/no-extraneous-dependencies
3
+ import TypeScriptModule from 'typescript'; // eslint-disable-line import/no-extraneous-dependencies
5
4
  import type {ParseConfigHost as IParseConfigHost} from 'typescript'; // eslint-disable-line import/no-extraneous-dependencies
6
5
  import {FSHost} from './FSHost';
7
6
 
@@ -9,13 +8,14 @@ export class ParseConfigHost extends FSHost implements IParseConfigHost {
9
8
  filesRead: Set<FilePath>;
10
9
  useCaseSensitiveFileNames: boolean;
11
10
 
11
+ // @ts-expect-error Cannot use namespace 'TypeScriptModule' as a type.
12
12
  constructor(fs: FileSystem, ts: TypeScriptModule) {
13
13
  super(fs, ts);
14
14
  this.filesRead = new Set();
15
15
  this.useCaseSensitiveFileNames = ts.sys.useCaseSensitiveFileNames;
16
16
  }
17
17
 
18
- readFile(filePath: FilePath): void | string {
18
+ readFile(filePath: FilePath): undefined | string {
19
19
  this.filesRead.add(filePath);
20
20
  return super.readFile(filePath);
21
21
  }
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  export {FSHost} from './FSHost';
3
2
  export {CompilerHost} from './CompilerHost';
4
3
  export {ParseConfigHost} from './ParseConfigHost';
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import type {Config, PluginOptions} from '@atlaspack/types';
3
2
  import {ParseConfigHost} from './ParseConfigHost';
4
3
  import path from 'path';
@@ -8,7 +7,7 @@ import ts from 'typescript';
8
7
  export async function loadTSConfig(
9
8
  config: Config,
10
9
  options: PluginOptions,
11
- ): any {
10
+ ): Promise<any> {
12
11
  let configResult = await config.getConfig(['tsconfig.json']);
13
12
  if (!configResult) {
14
13
  return;
package/tsconfig.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "../../../tsconfig.json",
3
+ "include": ["src"]
4
+ }