@flex-development/mlly 1.0.0-alpha.1
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 +149 -0
- package/LICENSE.md +28 -0
- package/README.md +17 -0
- package/changelog.config.cts +204 -0
- package/dist/constants.d.mts +19 -0
- package/dist/constants.mjs +24 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.mjs +4 -0
- package/dist/interfaces/import-dynamic.d.mts +23 -0
- package/dist/interfaces/import-dynamic.mjs +0 -0
- package/dist/interfaces/import-static.d.mts +19 -0
- package/dist/interfaces/import-static.mjs +0 -0
- package/dist/interfaces/index.d.mts +12 -0
- package/dist/interfaces/index.mjs +0 -0
- package/dist/interfaces/options-resolve-alias.d.mts +69 -0
- package/dist/interfaces/options-resolve-alias.mjs +0 -0
- package/dist/interfaces/options-resolve.d.mts +60 -0
- package/dist/interfaces/options-resolve.mjs +0 -0
- package/dist/interfaces/statement-export.d.mts +31 -0
- package/dist/interfaces/statement-export.mjs +0 -0
- package/dist/interfaces/statement-import.d.mts +27 -0
- package/dist/interfaces/statement-import.mjs +0 -0
- package/dist/interfaces/statement-require.d.mts +27 -0
- package/dist/interfaces/statement-require.mjs +0 -0
- package/dist/interfaces/statement.d.mts +33 -0
- package/dist/interfaces/statement.mjs +0 -0
- package/dist/internal/compiler-options-json.d.mts +111 -0
- package/dist/internal/compiler-options-json.mjs +0 -0
- package/dist/internal/constants.d.mts +70 -0
- package/dist/internal/constants.mjs +18 -0
- package/dist/internal/get-compiler-options.d.mts +21 -0
- package/dist/internal/get-compiler-options.mjs +14 -0
- package/dist/internal/index.d.mts +7 -0
- package/dist/internal/index.mjs +5 -0
- package/dist/lib/detect-syntax.d.mts +21 -0
- package/dist/lib/detect-syntax.mjs +11 -0
- package/dist/lib/extract-statements.d.mts +21 -0
- package/dist/lib/extract-statements.mjs +18 -0
- package/dist/lib/find-dynamic-imports.d.mts +15 -0
- package/dist/lib/find-dynamic-imports.mjs +20 -0
- package/dist/lib/find-exports.d.mts +15 -0
- package/dist/lib/find-exports.mjs +53 -0
- package/dist/lib/find-requires.d.mts +17 -0
- package/dist/lib/find-requires.mjs +19 -0
- package/dist/lib/find-static-imports.d.mts +15 -0
- package/dist/lib/find-static-imports.mjs +20 -0
- package/dist/lib/has-cjs-syntax.d.mts +22 -0
- package/dist/lib/has-cjs-syntax.mjs +6 -0
- package/dist/lib/has-esm-syntax.d.mts +18 -0
- package/dist/lib/has-esm-syntax.mjs +6 -0
- package/dist/lib/index.d.mts +20 -0
- package/dist/lib/index.mjs +34 -0
- package/dist/lib/resolve-alias.d.mts +20 -0
- package/dist/lib/resolve-alias.mjs +41 -0
- package/dist/lib/resolve-aliases.d.mts +17 -0
- package/dist/lib/resolve-aliases.mjs +34 -0
- package/dist/lib/resolve-module.d.mts +31 -0
- package/dist/lib/resolve-module.mjs +74 -0
- package/dist/lib/resolve-modules.d.mts +19 -0
- package/dist/lib/resolve-modules.mjs +29 -0
- package/dist/lib/to-absolute-specifier.d.mts +22 -0
- package/dist/lib/to-absolute-specifier.mjs +20 -0
- package/dist/lib/to-bare-specifier.d.mts +28 -0
- package/dist/lib/to-bare-specifier.mjs +78 -0
- package/dist/lib/to-data-url.d.mts +29 -0
- package/dist/lib/to-data-url.mjs +7 -0
- package/dist/lib/to-relative-specifier.d.mts +22 -0
- package/dist/lib/to-relative-specifier.mjs +17 -0
- package/dist/types/declaration.d.mts +9 -0
- package/dist/types/declaration.mjs +0 -0
- package/dist/types/ext.d.mts +9 -0
- package/dist/types/ext.mjs +0 -0
- package/dist/types/index.d.mts +9 -0
- package/dist/types/index.mjs +0 -0
- package/dist/types/mime-type.d.mts +11 -0
- package/dist/types/mime-type.mjs +0 -0
- package/dist/types/specifier-type.d.mts +11 -0
- package/dist/types/specifier-type.mjs +0 -0
- package/dist/types/statement-type.d.mts +9 -0
- package/dist/types/statement-type.mjs +0 -0
- package/package.json +197 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Interfaces - ResolveOptions
|
|
3
|
+
* @module mlly/interfaces/ResolveOptions
|
|
4
|
+
*/
|
|
5
|
+
/// <reference types="node" />
|
|
6
|
+
import type { Ext, SpecifierType } from '../types/index.mjs';
|
|
7
|
+
import type { EmptyString } from '@flex-development/tutils';
|
|
8
|
+
import type { URL } from 'node:url';
|
|
9
|
+
/**
|
|
10
|
+
* Module resolution options.
|
|
11
|
+
*/
|
|
12
|
+
interface ResolveOptions {
|
|
13
|
+
/**
|
|
14
|
+
* Export conditions.
|
|
15
|
+
*
|
|
16
|
+
* **Note**: Should be sorted by priority.
|
|
17
|
+
*
|
|
18
|
+
* @see https://nodejs.org/api/packages.html#conditional-exports
|
|
19
|
+
*
|
|
20
|
+
* @default CONDITIONS
|
|
21
|
+
*/
|
|
22
|
+
conditions?: Set<string> | string[] | readonly string[];
|
|
23
|
+
/**
|
|
24
|
+
* Remove or replace file extension.
|
|
25
|
+
*
|
|
26
|
+
* **Note**: {@link type} must be set to `relative`.
|
|
27
|
+
*
|
|
28
|
+
* @see {@link Ext}
|
|
29
|
+
*/
|
|
30
|
+
ext?: Ext | false | ((specifier: string, resolved: string) => EmptyString | Ext | PromiseLike<EmptyString | Ext>);
|
|
31
|
+
/**
|
|
32
|
+
* Module extensions to probe for.
|
|
33
|
+
*
|
|
34
|
+
* **Note**: Should be sorted by priority.
|
|
35
|
+
*
|
|
36
|
+
* @default RESOLVE_EXTENSIONS
|
|
37
|
+
*/
|
|
38
|
+
extensions?: string[] | readonly string[];
|
|
39
|
+
/**
|
|
40
|
+
* Parent module URL or path to resolve from.
|
|
41
|
+
*
|
|
42
|
+
* @default import.meta.url
|
|
43
|
+
*/
|
|
44
|
+
parent?: URL | string;
|
|
45
|
+
/**
|
|
46
|
+
* Keep symlinks instead of resolving them.
|
|
47
|
+
*
|
|
48
|
+
* @default false
|
|
49
|
+
*/
|
|
50
|
+
preserveSymlinks?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Module specifier type or a function to determine module specifier type.
|
|
53
|
+
*
|
|
54
|
+
* @see {@link SpecifierType}
|
|
55
|
+
*
|
|
56
|
+
* @default 'absolute'
|
|
57
|
+
*/
|
|
58
|
+
type?: SpecifierType | ((resolved: string) => PromiseLike<SpecifierType> | SpecifierType);
|
|
59
|
+
}
|
|
60
|
+
export type { ResolveOptions as default };
|
|
File without changes
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Interfaces - ExportStatement
|
|
3
|
+
* @module mlly/interfaces/ExportStatement
|
|
4
|
+
*/
|
|
5
|
+
import type { Declaration } from '../types/index.mjs';
|
|
6
|
+
import type Statement from './statement.mjs';
|
|
7
|
+
/**
|
|
8
|
+
* Export statement object schema.
|
|
9
|
+
*
|
|
10
|
+
* @see {@link Declaration}
|
|
11
|
+
* @see {@link Statement}
|
|
12
|
+
*
|
|
13
|
+
* @extends {Statement}
|
|
14
|
+
*/
|
|
15
|
+
interface ExportStatement extends Statement {
|
|
16
|
+
/**
|
|
17
|
+
* Export declaration, if any.
|
|
18
|
+
*
|
|
19
|
+
* @see {@link Declaration}
|
|
20
|
+
*/
|
|
21
|
+
declaration: Declaration | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Export names.
|
|
24
|
+
*/
|
|
25
|
+
exports: string[];
|
|
26
|
+
/**
|
|
27
|
+
* Export statement type.
|
|
28
|
+
*/
|
|
29
|
+
type: 'declaration' | 'default' | 'named' | 'star';
|
|
30
|
+
}
|
|
31
|
+
export type { ExportStatement as default };
|
|
File without changes
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Interfaces - ImportStatement
|
|
3
|
+
* @module mlly/interfaces/ImportStatement
|
|
4
|
+
*/
|
|
5
|
+
import type Statement from './statement.mjs';
|
|
6
|
+
/**
|
|
7
|
+
* Import statement object schema.
|
|
8
|
+
*
|
|
9
|
+
* @see {@link Statement}
|
|
10
|
+
*
|
|
11
|
+
* @extends {Statement}
|
|
12
|
+
*/
|
|
13
|
+
interface ImportStatement extends Statement {
|
|
14
|
+
/**
|
|
15
|
+
* Import names.
|
|
16
|
+
*/
|
|
17
|
+
imports: string[];
|
|
18
|
+
/**
|
|
19
|
+
* Module specifier.
|
|
20
|
+
*/
|
|
21
|
+
specifier: NonNullable<Statement['specifier']>;
|
|
22
|
+
/**
|
|
23
|
+
* Import statement type.
|
|
24
|
+
*/
|
|
25
|
+
type: 'default' | 'dynamic' | 'named' | 'star';
|
|
26
|
+
}
|
|
27
|
+
export type { ImportStatement as default };
|
|
File without changes
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Interfaces - RequireStatement
|
|
3
|
+
* @module mlly/interfaces/RequireStatement
|
|
4
|
+
*/
|
|
5
|
+
import type Statement from './statement.mjs';
|
|
6
|
+
/**
|
|
7
|
+
* Require statement object schema.
|
|
8
|
+
*
|
|
9
|
+
* @see {@link Statement}
|
|
10
|
+
*
|
|
11
|
+
* @extends {Statement}
|
|
12
|
+
*/
|
|
13
|
+
interface RequireStatement extends Statement {
|
|
14
|
+
/**
|
|
15
|
+
* Import names.
|
|
16
|
+
*/
|
|
17
|
+
imports: string[];
|
|
18
|
+
/**
|
|
19
|
+
* Module specifier.
|
|
20
|
+
*/
|
|
21
|
+
specifier: NonNullable<Statement['specifier']>;
|
|
22
|
+
/**
|
|
23
|
+
* Import statement type.
|
|
24
|
+
*/
|
|
25
|
+
type: 'require';
|
|
26
|
+
}
|
|
27
|
+
export type { RequireStatement as default };
|
|
File without changes
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Interfaces - Statement
|
|
3
|
+
* @module mlly/interfaces/Statement
|
|
4
|
+
*/
|
|
5
|
+
import type { StatementType } from '../types/index.mjs';
|
|
6
|
+
/**
|
|
7
|
+
* CommonJS or ESM statement object schema.
|
|
8
|
+
*
|
|
9
|
+
* @see {@link StatementType}
|
|
10
|
+
*/
|
|
11
|
+
interface Statement {
|
|
12
|
+
/**
|
|
13
|
+
* Statement snippet.
|
|
14
|
+
*/
|
|
15
|
+
code: string;
|
|
16
|
+
/**
|
|
17
|
+
* Ending index of {@link code} in source content.
|
|
18
|
+
*/
|
|
19
|
+
end: number;
|
|
20
|
+
/**
|
|
21
|
+
* Module specifier.
|
|
22
|
+
*/
|
|
23
|
+
specifier: string | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Starting index of {@link code} in source content.
|
|
26
|
+
*/
|
|
27
|
+
start: number;
|
|
28
|
+
/**
|
|
29
|
+
* Statement type.
|
|
30
|
+
*/
|
|
31
|
+
type: StatementType;
|
|
32
|
+
}
|
|
33
|
+
export type { Statement as default };
|
|
File without changes
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Internals - CompilerOptionsJson
|
|
3
|
+
* @module mlly/internal/CompilerOptionsJson
|
|
4
|
+
*/
|
|
5
|
+
import type { CompilerOptionsValue, MapLike } from 'typescript';
|
|
6
|
+
/**
|
|
7
|
+
* TypeScript compiler options provided by a user.
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*
|
|
11
|
+
* @see https://www.typescriptlang.org/tsconfig
|
|
12
|
+
*/
|
|
13
|
+
interface CompilerOptionsJson {
|
|
14
|
+
allowJs?: boolean;
|
|
15
|
+
allowSyntheticDefaultImports?: boolean;
|
|
16
|
+
allowUmdGlobalAccess?: boolean;
|
|
17
|
+
allowUnreachableCode?: boolean;
|
|
18
|
+
allowUnusedLabels?: boolean;
|
|
19
|
+
alwaysStrict?: boolean;
|
|
20
|
+
assumeChangesOnlyAffectDirectDependencies?: boolean;
|
|
21
|
+
baseUrl?: string;
|
|
22
|
+
charset?: string;
|
|
23
|
+
checkJs?: boolean;
|
|
24
|
+
composite?: boolean;
|
|
25
|
+
declaration?: boolean;
|
|
26
|
+
declarationDir?: string;
|
|
27
|
+
declarationMap?: boolean;
|
|
28
|
+
disableReferencedProjectLoad?: boolean;
|
|
29
|
+
disableSizeLimit?: boolean;
|
|
30
|
+
disableSolutionSearching?: boolean;
|
|
31
|
+
disableSourceOfProjectReferenceRedirect?: boolean;
|
|
32
|
+
downlevelIteration?: boolean;
|
|
33
|
+
emitBOM?: boolean;
|
|
34
|
+
emitDeclarationOnly?: boolean;
|
|
35
|
+
emitDecoratorMetadata?: boolean;
|
|
36
|
+
esModuleInterop?: boolean;
|
|
37
|
+
exactOptionalPropertyTypes?: boolean;
|
|
38
|
+
experimentalDecorators?: boolean;
|
|
39
|
+
forceConsistentCasingInFileNames?: boolean;
|
|
40
|
+
importHelpers?: boolean;
|
|
41
|
+
importsNotUsedAsValues?: 'error' | 'preserve' | 'remove';
|
|
42
|
+
incremental?: boolean;
|
|
43
|
+
inlineSourceMap?: boolean;
|
|
44
|
+
inlineSources?: boolean;
|
|
45
|
+
isolatedModules?: boolean;
|
|
46
|
+
jsx?: 'preserve' | 'react-jsx' | 'react-jsxdev' | 'react-native' | 'react';
|
|
47
|
+
jsxFactory?: string;
|
|
48
|
+
jsxFragmentFactory?: string;
|
|
49
|
+
jsxImportSource?: string;
|
|
50
|
+
keyofStringsOnly?: boolean;
|
|
51
|
+
lib?: ('DOM.Iterable' | 'dom.iterable' | 'DOM' | 'dom' | 'ES5' | 'es5' | 'ES6' | 'es6' | 'ES7' | 'es7' | 'ES2015.Collection' | 'es2015.collection' | 'ES2015.Core' | 'es2015.core' | 'ES2015.Generator' | 'es2015.generator' | 'ES2015.Iterable' | 'es2015.iterable' | 'ES2015.Promise' | 'es2015.promise' | 'ES2015.Proxy' | 'es2015.proxy' | 'ES2015.Reflect' | 'es2015.reflect' | 'ES2015.Symbol.WellKnown' | 'es2015.symbol.wellknown' | 'ES2015.Symbol' | 'es2015.symbol' | 'ES2015' | 'es2015' | 'ES2016.Array.Include' | 'es2016.array.include' | 'ES2016' | 'es2016' | 'ES2017.Intl' | 'es2017.intl' | 'ES2017.Object' | 'es2017.object' | 'ES2017.SharedMemory' | 'es2017.sharedmemory' | 'ES2017.String' | 'es2017.string' | 'ES2017.TypedArrays' | 'es2017.typedarrays' | 'ES2017' | 'es2017' | 'ES2018.AsyncGenerator' | 'es2018.asyncgenerator' | 'ES2018.AsyncIterable' | 'es2018.asynciterable' | 'ES2018.Intl' | 'es2018.intl' | 'ES2018.Promise' | 'es2018.promise' | 'ES2018.Regexp' | 'es2018.regexp' | 'ES2018' | 'es2018' | 'ES2019.Array' | 'es2019.array' | 'ES2019.Object' | 'es2019.object' | 'ES2019.String' | 'es2019.string' | 'ES2019.Symbol' | 'es2019.symbol' | 'ES2019' | 'es2019' | 'ES2020.BigInt' | 'es2020.bigint' | 'ES2020.Intl' | 'es2020.intl' | 'ES2020.Promise' | 'es2020.promise' | 'ES2020.SharedMemory' | 'es2020.sharedmemory' | 'ES2020.String' | 'es2020.string' | 'ES2020.Symbol.WellKnown' | 'es2020.symbol.wellknown' | 'ES2020' | 'es2020' | 'ES2021.Promise' | 'es2021.promise' | 'ES2021.String' | 'es2021.string' | 'ES2021.WeakRef' | 'es2021.weakref' | 'ES2021' | 'es2021' | 'ESNext.Array' | 'esnext.array' | 'ESNext.AsyncIterable' | 'esnext.asynciterable' | 'ESNext.BigInt' | 'esnext.bigint' | 'ESNext.Intl' | 'esnext.intl' | 'ESNext.Promise' | 'esnext.promise' | 'ESNext.String' | 'esnext.string' | 'ESNext.Symbol' | 'esnext.symbol' | 'ESNext.WeakRef' | 'esnext.weakref' | 'ESNext' | 'esnext' | 'ScriptHost' | 'scripthost' | 'WebWorker.ImportScripts' | 'webworker.importscripts' | 'WebWorker.Iterable' | 'webworker.iterable' | 'WebWorker' | 'webworker')[];
|
|
52
|
+
locale?: string;
|
|
53
|
+
mapRoot?: string;
|
|
54
|
+
maxNodeModuleJsDepth?: number;
|
|
55
|
+
module?: 'AMD' | 'amd' | 'CommonJS' | 'commonjs' | 'ES6' | 'es6' | 'ES2015' | 'es2015' | 'ES2020' | 'es2020' | 'ES2022' | 'es2022' | 'ESNext' | 'esnext' | 'Node16' | 'node16' | 'NodeNext' | 'nodenext' | 'None' | 'none' | 'System' | 'system' | 'UMD' | 'umd';
|
|
56
|
+
moduleDetection?: 'auto' | 'force' | 'legacy';
|
|
57
|
+
moduleResolution?: 'classic' | 'node' | 'node16' | 'nodenext';
|
|
58
|
+
moduleSuffixes?: string[];
|
|
59
|
+
newLine?: 'CRLF' | 'crlf' | 'LF' | 'lf';
|
|
60
|
+
noEmit?: boolean;
|
|
61
|
+
noEmitHelpers?: boolean;
|
|
62
|
+
noEmitOnError?: boolean;
|
|
63
|
+
noErrorTruncation?: boolean;
|
|
64
|
+
noFallthroughCasesInSwitch?: boolean;
|
|
65
|
+
noImplicitAny?: boolean;
|
|
66
|
+
noImplicitOverride?: boolean;
|
|
67
|
+
noImplicitReturns?: boolean;
|
|
68
|
+
noImplicitThis?: boolean;
|
|
69
|
+
noImplicitUseStrict?: boolean;
|
|
70
|
+
noLib?: boolean;
|
|
71
|
+
noPropertyAccessFromIndexSignature?: boolean;
|
|
72
|
+
noResolve?: boolean;
|
|
73
|
+
noStrictGenericChecks?: boolean;
|
|
74
|
+
noUncheckedIndexedAccess?: boolean;
|
|
75
|
+
noUnusedLocals?: boolean;
|
|
76
|
+
noUnusedParameters?: boolean;
|
|
77
|
+
out?: string;
|
|
78
|
+
outDir?: string;
|
|
79
|
+
outFile?: string;
|
|
80
|
+
paths?: MapLike<string[]>;
|
|
81
|
+
preserveConstEnums?: boolean;
|
|
82
|
+
preserveSymlinks?: boolean;
|
|
83
|
+
preserveValueImports?: boolean;
|
|
84
|
+
project?: string;
|
|
85
|
+
reactNamespace?: string;
|
|
86
|
+
removeComments?: boolean;
|
|
87
|
+
resolveJsonModule?: boolean;
|
|
88
|
+
rootDir?: string;
|
|
89
|
+
rootDirs?: string[];
|
|
90
|
+
skipDefaultLibCheck?: boolean;
|
|
91
|
+
skipLibCheck?: boolean;
|
|
92
|
+
sourceMap?: boolean;
|
|
93
|
+
sourceRoot?: string;
|
|
94
|
+
strict?: boolean;
|
|
95
|
+
strictBindCallApply?: boolean;
|
|
96
|
+
strictFunctionTypes?: boolean;
|
|
97
|
+
strictNullChecks?: boolean;
|
|
98
|
+
strictPropertyInitialization?: boolean;
|
|
99
|
+
stripInternal?: boolean;
|
|
100
|
+
suppressExcessPropertyErrors?: boolean;
|
|
101
|
+
suppressImplicitAnyIndexErrors?: boolean;
|
|
102
|
+
target?: 'ES3' | 'es3' | 'ES5' | 'es5' | 'ES6' | 'es6' | 'ES2015' | 'es2015' | 'ES2016' | 'es2016' | 'ES2017' | 'es2017' | 'ES2018' | 'es2018' | 'ES2019' | 'es2019' | 'ES2020' | 'es2020' | 'ES2021' | 'es2021' | 'ESNext' | 'esnext';
|
|
103
|
+
traceResolution?: boolean;
|
|
104
|
+
tsBuildInfoFile?: string;
|
|
105
|
+
typeRoots?: string[];
|
|
106
|
+
types?: string[];
|
|
107
|
+
useDefineForClassFields?: boolean;
|
|
108
|
+
useUnknownInCatchVariables?: boolean;
|
|
109
|
+
[option: string]: CompilerOptionsValue | undefined;
|
|
110
|
+
}
|
|
111
|
+
export type { CompilerOptionsJson as default };
|
|
File without changes
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Internals - Constants
|
|
3
|
+
* @module mlly/internal/constants
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* CommonJS syntax regex.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*
|
|
10
|
+
* @const {RegExp} CJS_SYNTAX_REGEX
|
|
11
|
+
*/
|
|
12
|
+
export declare const CJS_SYNTAX_REGEX: RegExp;
|
|
13
|
+
/**
|
|
14
|
+
* Dynamic import statement regex.
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*
|
|
18
|
+
* @const {RegExp} DYNAMIC_IMPORT_REGEX
|
|
19
|
+
*/
|
|
20
|
+
export declare const DYNAMIC_IMPORT_REGEX: RegExp;
|
|
21
|
+
/**
|
|
22
|
+
* ESM syntax regex.
|
|
23
|
+
*
|
|
24
|
+
* @internal
|
|
25
|
+
*
|
|
26
|
+
* @const {RegExp} ESM_SYNTAX_REGEX
|
|
27
|
+
*/
|
|
28
|
+
export declare const ESM_SYNTAX_REGEX: RegExp;
|
|
29
|
+
/**
|
|
30
|
+
* Declaration export statement regex.
|
|
31
|
+
*
|
|
32
|
+
* **Note**: Captures [declaration type][1] and export name only.
|
|
33
|
+
*
|
|
34
|
+
* [1]: ./types/declaration.ts
|
|
35
|
+
*
|
|
36
|
+
* @const {RegExp} EXPORT_DECLARATION_REGEX
|
|
37
|
+
*/
|
|
38
|
+
export declare const EXPORT_DECLARATION_REGEX: RegExp;
|
|
39
|
+
/**
|
|
40
|
+
* Named export statement regex.
|
|
41
|
+
*
|
|
42
|
+
* @internal
|
|
43
|
+
*
|
|
44
|
+
* @const {RegExp} EXPORT_NAMED_REGEX
|
|
45
|
+
*/
|
|
46
|
+
export declare const EXPORT_NAMED_REGEX: RegExp;
|
|
47
|
+
/**
|
|
48
|
+
* Aggregate export statement (`export * ...`) regex.
|
|
49
|
+
*
|
|
50
|
+
* @internal
|
|
51
|
+
*
|
|
52
|
+
* @const {RegExp} EXPORT_STAR_REGEX
|
|
53
|
+
*/
|
|
54
|
+
export declare const EXPORT_STAR_REGEX: RegExp;
|
|
55
|
+
/**
|
|
56
|
+
* Require statement regex.
|
|
57
|
+
*
|
|
58
|
+
* @internal
|
|
59
|
+
*
|
|
60
|
+
* @const {RegExp} REQUIRE_STATEMENT_REGEX
|
|
61
|
+
*/
|
|
62
|
+
export declare const REQUIRE_STATEMENT_REGEX: RegExp;
|
|
63
|
+
/**
|
|
64
|
+
* Static import statement regex.
|
|
65
|
+
*
|
|
66
|
+
* @internal
|
|
67
|
+
*
|
|
68
|
+
* @const {RegExp} STATIC_IMPORT_REGEX
|
|
69
|
+
*/
|
|
70
|
+
export declare const STATIC_IMPORT_REGEX: RegExp;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const CJS_SYNTAX_REGEX = /(?<!(?:\/\/|\*).*)((?:module\.)?exports(?:\.\w+|(?<!\s+=))|require(?=\(.)|require\.\w+|__dirname|__filename|await import)/gm;
|
|
2
|
+
const DYNAMIC_IMPORT_REGEX = /(?<!(?:\/\/|\*).*)(?:(?:const|let|var)(?:(?<name>\s+\w+\s*)|\s*{\s*(?<names>\w+(?:,\s*\w+)*)\s*}\s*)(?:\s*=\s*?)?.)?(?:await)?\s+import\s*\((?<expression>(?:[^()]+|\((?:[^()]+|\([^()]*\))*\))*)\)/gm;
|
|
3
|
+
const ESM_SYNTAX_REGEX = /(?<!(?:\/\/|\*).*)((?:export|import)[\s\w*,{}]*(?=\sfrom)|export\b\s*(?:[*{]|async function|(?:abstract\s)?class|const|default|enum|function|interface|let|type|var)|await import|import\.meta\.(?:env(?:\.\w+)?|resolve|url))/gm;
|
|
4
|
+
const EXPORT_DECLARATION_REGEX = /(?<!(?:\/\/|\*).*)\bexport(?: +declare)? +(?<declaration>(?:(?:abstract +)?class|(?:default +)?async +function\*?|(?:default +)?function\*?|default +async|default(?!(?: +async)? +function\*?)|(?:const +)?enum|const|interface|let|namespace|type(?! *{)|var)) +(?<name>[\w$]+(?!.*\b +=>))?/gm;
|
|
5
|
+
const EXPORT_NAMED_REGEX = /(?<!(?:\/\/|\*).*)\bexport(?:\s+type)?\s+{(?<exports>[^}]+?)[\s,]*}(?:\s*from\s*["']\s*(?<specifier>(?<="\s*)[^"]*[^\s"](?=\s*")|(?<='\s*)[^']*[^\s'](?=\s*'))\s*["'][^\n;]*)?/gm;
|
|
6
|
+
const EXPORT_STAR_REGEX = /(?<!(?:\/\/|\*).*)\bexport\s*\*(?:\s*as\s+(?<name>[\w$]+)\s+)?\s*(?:\s*from\s*["']\s*(?<specifier>(?<="\s*)[^"]*[^\s"](?=\s*")|(?<='\s*)[^']*[^\s'](?=\s*'))\s*["'][^\n;]*)?/gm;
|
|
7
|
+
const REQUIRE_STATEMENT_REGEX = /(?<!(?:\/\/|\*).*)(?:\bconst[ {]+(?<imports>[\w\t\n\r $*,/]+)[ =}]+)?(?<type>\brequire(?:\.resolve)?)\(["'] *(?<specifier>(?<="\s*)[^"']*[^\s"'](?=\s*")|(?<=["']\s*)[^']*[^\s'](?=\s*')) *["']\)/gm;
|
|
8
|
+
const STATIC_IMPORT_REGEX = /(?<!(?:\/\/|\*).*)(?<=\s|^|;)import\s*([\s"']*(?<imports>[\w\t\n\r $*,/{}]+)from\s*)?["']\s*(?<specifier>(?<="\s*)[^"]*[^\s"](?=\s*")|(?<='\s*)[^']*[^\s'](?=\s*'))\s*["'][\s;]*/gm;
|
|
9
|
+
export {
|
|
10
|
+
CJS_SYNTAX_REGEX,
|
|
11
|
+
DYNAMIC_IMPORT_REGEX,
|
|
12
|
+
ESM_SYNTAX_REGEX,
|
|
13
|
+
EXPORT_DECLARATION_REGEX,
|
|
14
|
+
EXPORT_NAMED_REGEX,
|
|
15
|
+
EXPORT_STAR_REGEX,
|
|
16
|
+
REQUIRE_STATEMENT_REGEX,
|
|
17
|
+
STATIC_IMPORT_REGEX
|
|
18
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Internals - getCompilerOptions
|
|
3
|
+
* @module mlly/internal/getCompilerOptions
|
|
4
|
+
*/
|
|
5
|
+
import type CompilerOptionsJson from './compiler-options-json.mjs';
|
|
6
|
+
/**
|
|
7
|
+
* Retrieves TypeScript compiler options from `path`.
|
|
8
|
+
*
|
|
9
|
+
* Supports [`extends`][1].
|
|
10
|
+
*
|
|
11
|
+
* [1]: https://typescriptlang.org/tsconfig#extends
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
14
|
+
*
|
|
15
|
+
* @param {string} [path=upath.resolve('tsconfig.json')] - Tsconfig path
|
|
16
|
+
* @param {(path: string) => boolean} [exists] - File existence checker
|
|
17
|
+
* @param {(filename: string) => string} [read] - File content reader
|
|
18
|
+
* @return {CompilerOptionsJson} User compiler options
|
|
19
|
+
*/
|
|
20
|
+
declare const getCompilerOptions: (path?: string, exists?: ((path: string) => boolean) | undefined, read?: ((filename: string) => string) | undefined) => CompilerOptionsJson;
|
|
21
|
+
export default getCompilerOptions;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { loadTsconfig } from "tsconfig-paths/lib/tsconfig-loader.js";
|
|
2
|
+
import upath from "upath";
|
|
3
|
+
const getCompilerOptions = (path = upath.resolve("tsconfig.json"), exists, read) => {
|
|
4
|
+
const t = loadTsconfig(
|
|
5
|
+
path,
|
|
6
|
+
exists,
|
|
7
|
+
read
|
|
8
|
+
);
|
|
9
|
+
return !(t == null ? void 0 : t.compilerOptions) ? {} : t.compilerOptions;
|
|
10
|
+
};
|
|
11
|
+
var get_compiler_options_default = getCompilerOptions;
|
|
12
|
+
export {
|
|
13
|
+
get_compiler_options_default as default
|
|
14
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file detectSyntax
|
|
3
|
+
* @module mlly/lib/detectSyntax
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Detects if `code` contains CommonJS syntax, ESM syntax, or a mixture of both.
|
|
7
|
+
*
|
|
8
|
+
* Ignores matches in comments.
|
|
9
|
+
*
|
|
10
|
+
* @see {@link hasCJSSyntax}
|
|
11
|
+
* @see {@link hasESMSyntax}
|
|
12
|
+
*
|
|
13
|
+
* @param {string} code - Code to check
|
|
14
|
+
* @return {{ cjs: boolean; esm: boolean; mixed: boolean }} Detection result
|
|
15
|
+
*/
|
|
16
|
+
declare const detectSyntax: (code: string) => {
|
|
17
|
+
cjs: boolean;
|
|
18
|
+
esm: boolean;
|
|
19
|
+
mixed: boolean;
|
|
20
|
+
};
|
|
21
|
+
export default detectSyntax;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import hasCJSSyntax from "./has-cjs-syntax.mjs";
|
|
2
|
+
import hasESMSyntax from "./has-esm-syntax.mjs";
|
|
3
|
+
const detectSyntax = (code) => {
|
|
4
|
+
const cjs = hasCJSSyntax(code);
|
|
5
|
+
const esm = hasESMSyntax(code);
|
|
6
|
+
return { cjs, esm, mixed: cjs && esm };
|
|
7
|
+
};
|
|
8
|
+
var detect_syntax_default = detectSyntax;
|
|
9
|
+
export {
|
|
10
|
+
detect_syntax_default as default
|
|
11
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file extractStatements
|
|
3
|
+
* @module mlly/lib/extractStatements
|
|
4
|
+
*/
|
|
5
|
+
import type { Statement } from '../interfaces/index.mjs';
|
|
6
|
+
/**
|
|
7
|
+
* Finds all `export`, `import`, `require`, and/or `require.resolve` statements
|
|
8
|
+
* in `code`.
|
|
9
|
+
*
|
|
10
|
+
* Ignores matches in comments.
|
|
11
|
+
*
|
|
12
|
+
* @see {@link findDynamicImports}
|
|
13
|
+
* @see {@link findExports}
|
|
14
|
+
* @see {@link findRequires}
|
|
15
|
+
* @see {@link findStaticImports}
|
|
16
|
+
*
|
|
17
|
+
* @param {string} [code=''] - Code to extract statements from
|
|
18
|
+
* @return {Statement[]} Extracted statements
|
|
19
|
+
*/
|
|
20
|
+
declare const extractStatements: (code?: string) => Statement[];
|
|
21
|
+
export default extractStatements;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import findDynamicImports from "./find-dynamic-imports.mjs";
|
|
2
|
+
import findExports from "./find-exports.mjs";
|
|
3
|
+
import findRequires from "./find-requires.mjs";
|
|
4
|
+
import findStaticImports from "./find-static-imports.mjs";
|
|
5
|
+
const extractStatements = (code = "") => {
|
|
6
|
+
if (!code)
|
|
7
|
+
return [];
|
|
8
|
+
return [
|
|
9
|
+
...findDynamicImports(code),
|
|
10
|
+
...findExports(code),
|
|
11
|
+
...findRequires(code),
|
|
12
|
+
...findStaticImports(code)
|
|
13
|
+
];
|
|
14
|
+
};
|
|
15
|
+
var extract_statements_default = extractStatements;
|
|
16
|
+
export {
|
|
17
|
+
extract_statements_default as default
|
|
18
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file findDynamicImports
|
|
3
|
+
* @module mlly/lib/findDynamicImports
|
|
4
|
+
*/
|
|
5
|
+
import type { DynamicImport } from '../interfaces/index.mjs';
|
|
6
|
+
/**
|
|
7
|
+
* Finds all dynamic import statements in `code`. Ignores matches in comments.
|
|
8
|
+
*
|
|
9
|
+
* @see {@link DynamicImport}
|
|
10
|
+
*
|
|
11
|
+
* @param {string} code - Code to check
|
|
12
|
+
* @return {DynamicImport[]} Dynamic import statement objects
|
|
13
|
+
*/
|
|
14
|
+
declare const findDynamicImports: (code: string) => DynamicImport[];
|
|
15
|
+
export default findDynamicImports;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DYNAMIC_IMPORT_REGEX } from "../internal/index.mjs";
|
|
2
|
+
const findDynamicImports = (code) => {
|
|
3
|
+
return [...code.matchAll(DYNAMIC_IMPORT_REGEX)].map((match) => {
|
|
4
|
+
const { 0: statement = "", index: start = 0, groups = {} } = match;
|
|
5
|
+
const { expression = "", name = "", names = "" } = groups;
|
|
6
|
+
return {
|
|
7
|
+
code: statement,
|
|
8
|
+
end: start + statement.length,
|
|
9
|
+
imports: name.trim() ? [name.trim()] : names.trim() ? names.split(",").map((name2) => name2.trim()) : [],
|
|
10
|
+
specifier: expression.replace(/["']/g, ""),
|
|
11
|
+
specifier_type: /^["']/g.test(expression) ? "static" : "dynamic",
|
|
12
|
+
start,
|
|
13
|
+
type: "dynamic"
|
|
14
|
+
};
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
var find_dynamic_imports_default = findDynamicImports;
|
|
18
|
+
export {
|
|
19
|
+
find_dynamic_imports_default as default
|
|
20
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file findExports
|
|
3
|
+
* @module mlly/lib/findExports
|
|
4
|
+
*/
|
|
5
|
+
import type { ExportStatement } from '../interfaces/index.mjs';
|
|
6
|
+
/**
|
|
7
|
+
* Finds all export statements in `code`. Ignores matches in comments.
|
|
8
|
+
*
|
|
9
|
+
* @see {@link ExportStatement}
|
|
10
|
+
*
|
|
11
|
+
* @param {string} code - Code to check
|
|
12
|
+
* @return {ExportStatement[]} Export statement objects
|
|
13
|
+
*/
|
|
14
|
+
declare const findExports: (code: string) => ExportStatement[];
|
|
15
|
+
export default findExports;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EXPORT_DECLARATION_REGEX,
|
|
3
|
+
EXPORT_NAMED_REGEX,
|
|
4
|
+
EXPORT_STAR_REGEX
|
|
5
|
+
} from "../internal/index.mjs";
|
|
6
|
+
const findExports = (code) => {
|
|
7
|
+
const statements = [];
|
|
8
|
+
for (const match of code.matchAll(EXPORT_DECLARATION_REGEX)) {
|
|
9
|
+
const { 0: statement = "", index: start = 0, groups = {} } = match;
|
|
10
|
+
const { declaration = "default", name = "" } = groups;
|
|
11
|
+
const stmt = statement.trim();
|
|
12
|
+
statements.push({
|
|
13
|
+
code: stmt,
|
|
14
|
+
declaration,
|
|
15
|
+
end: start + stmt.length,
|
|
16
|
+
exports: [name === "" ? "default" : name.trim()],
|
|
17
|
+
specifier: void 0,
|
|
18
|
+
start,
|
|
19
|
+
type: declaration === "default" ? "default" : "declaration"
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
for (const match of code.matchAll(EXPORT_NAMED_REGEX)) {
|
|
23
|
+
const { 0: statement = "", index: start = 0, groups = {} } = match;
|
|
24
|
+
const { exports: exp = "", specifier = "" } = groups;
|
|
25
|
+
statements.push({
|
|
26
|
+
code: statement,
|
|
27
|
+
declaration: void 0,
|
|
28
|
+
end: start + statement.length,
|
|
29
|
+
exports: exp.split(",").map((name) => name.trim()),
|
|
30
|
+
specifier,
|
|
31
|
+
start,
|
|
32
|
+
type: exp.trim() === "default" ? "default" : "named"
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
for (const match of code.matchAll(EXPORT_STAR_REGEX)) {
|
|
36
|
+
const { 0: statement = "", index: start = 0, groups = {} } = match;
|
|
37
|
+
const { name = "*", specifier = "" } = groups;
|
|
38
|
+
statements.push({
|
|
39
|
+
code: statement,
|
|
40
|
+
declaration: void 0,
|
|
41
|
+
end: start + statement.length,
|
|
42
|
+
exports: [name === "*" ? name : name.replace(/(\w+)/, "* as $1").trim()],
|
|
43
|
+
specifier,
|
|
44
|
+
start,
|
|
45
|
+
type: "star"
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return statements;
|
|
49
|
+
};
|
|
50
|
+
var find_exports_default = findExports;
|
|
51
|
+
export {
|
|
52
|
+
find_exports_default as default
|
|
53
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file findRequires
|
|
3
|
+
* @module mlly/lib/findRequires
|
|
4
|
+
*/
|
|
5
|
+
import type { RequireStatement } from '../interfaces/index.mjs';
|
|
6
|
+
/**
|
|
7
|
+
* Finds all `require` and `require.resolve` statements in `code`.
|
|
8
|
+
*
|
|
9
|
+
* Ignores matches in comments.
|
|
10
|
+
*
|
|
11
|
+
* @see {@link RequireStatement}
|
|
12
|
+
*
|
|
13
|
+
* @param {string} code - Code to check
|
|
14
|
+
* @return {RequireStatement[]} Require statement objects
|
|
15
|
+
*/
|
|
16
|
+
declare const findRequires: (code: string) => RequireStatement[];
|
|
17
|
+
export default findRequires;
|