@vaadin/hilla-generator-utils 24.6.0-beta2 → 24.6.0-beta4
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/dependencies/ExportManager.d.ts +4 -0
- package/dependencies/ExportManager.d.ts.map +1 -1
- package/dependencies/ExportManager.js +12 -0
- package/dependencies/ExportManager.js.map +2 -2
- package/dependencies/ImportManager.d.ts +4 -0
- package/dependencies/ImportManager.d.ts.map +1 -1
- package/dependencies/ImportManager.js +19 -2
- package/dependencies/ImportManager.js.map +2 -2
- package/dependencies/PathManager.d.ts +2 -2
- package/dependencies/PathManager.d.ts.map +1 -1
- package/dependencies/PathManager.js +11 -6
- package/dependencies/PathManager.js.map +2 -2
- package/package.json +1 -1
|
@@ -3,6 +3,7 @@ import type CodeConvertable from './CodeConvertable.js';
|
|
|
3
3
|
import StatementRecordManager, { type StatementRecord } from './StatementRecordManager.js';
|
|
4
4
|
export declare class NamedExportManager implements CodeConvertable<ExportDeclaration | undefined> {
|
|
5
5
|
#private;
|
|
6
|
+
get size(): number;
|
|
6
7
|
constructor(collator: Intl.Collator);
|
|
7
8
|
add(name: string, isType?: boolean, uniqueId?: Identifier): Identifier;
|
|
8
9
|
getIdentifier(name: string): Identifier | undefined;
|
|
@@ -13,6 +14,7 @@ export declare class NamedExportManager implements CodeConvertable<ExportDeclara
|
|
|
13
14
|
}
|
|
14
15
|
export declare class NamespaceExportManager extends StatementRecordManager<ExportDeclaration> {
|
|
15
16
|
#private;
|
|
17
|
+
get size(): number;
|
|
16
18
|
addCombined(path: string, name: string, uniqueId?: Identifier): Identifier;
|
|
17
19
|
addSpread(path: string): void;
|
|
18
20
|
clear(): void;
|
|
@@ -25,6 +27,7 @@ export declare class NamespaceExportManager extends StatementRecordManager<Expor
|
|
|
25
27
|
}
|
|
26
28
|
export declare class DefaultExportManager implements CodeConvertable<ExportAssignment | undefined> {
|
|
27
29
|
#private;
|
|
30
|
+
get isEmpty(): boolean;
|
|
28
31
|
set(id: Identifier | string): Identifier;
|
|
29
32
|
toCode(): ExportAssignment | undefined;
|
|
30
33
|
}
|
|
@@ -32,6 +35,7 @@ export default class ExportManager implements CodeConvertable<readonly Statement
|
|
|
32
35
|
readonly default: DefaultExportManager;
|
|
33
36
|
readonly named: NamedExportManager;
|
|
34
37
|
readonly namespace: NamespaceExportManager;
|
|
38
|
+
get size(): number;
|
|
35
39
|
constructor(collator: Intl.Collator);
|
|
36
40
|
toCode(): readonly Statement[];
|
|
37
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExportManager.d.ts","sourceRoot":"","sources":["../src/dependencies/ExportManager.ts"],"names":[],"mappings":"AAAA,OAAW,EAAE,KAAK,gBAAgB,EAAE,KAAK,iBAAiB,EAAE,KAAK,UAAU,EAAE,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAEhH,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAC;AACxD,OAAO,sBAAsB,EAAE,EAAE,KAAK,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAG3F,qBAAa,kBAAmB,YAAW,eAAe,CAAC,iBAAiB,GAAG,SAAS,CAAC;;
|
|
1
|
+
{"version":3,"file":"ExportManager.d.ts","sourceRoot":"","sources":["../src/dependencies/ExportManager.ts"],"names":[],"mappings":"AAAA,OAAW,EAAE,KAAK,gBAAgB,EAAE,KAAK,iBAAiB,EAAE,KAAK,UAAU,EAAE,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAEhH,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAC;AACxD,OAAO,sBAAsB,EAAE,EAAE,KAAK,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAG3F,qBAAa,kBAAmB,YAAW,eAAe,CAAC,iBAAiB,GAAG,SAAS,CAAC;;IAIvF,IAAI,IAAI,IAAI,MAAM,CAEjB;gBAEW,QAAQ,EAAE,IAAI,CAAC,QAAQ;IAInC,GAAG,CAAC,IAAI,EAAE,MAAM,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,SAAS;CAGvC;AAED,MAAM,CAAC,OAAO,OAAO,aAAc,YAAW,eAAe,CAAC,SAAS,SAAS,EAAE,CAAC;IACjF,QAAQ,CAAC,OAAO,uBAA8B;IAC9C,QAAQ,CAAC,KAAK,EAAE,kBAAkB,CAAC;IACnC,QAAQ,CAAC,SAAS,EAAE,sBAAsB,CAAC;IAE3C,IAAI,IAAI,IAAI,MAAM,CAEjB;gBAEW,QAAQ,EAAE,IAAI,CAAC,QAAQ;IAKnC,MAAM,IAAI,SAAS,SAAS,EAAE;CAmB/B"}
|
|
@@ -5,6 +5,9 @@ import { createDependencyRecord } from "./utils.js";
|
|
|
5
5
|
class NamedExportManager {
|
|
6
6
|
#collator;
|
|
7
7
|
#map = /* @__PURE__ */ new Map();
|
|
8
|
+
get size() {
|
|
9
|
+
return this.#map.size;
|
|
10
|
+
}
|
|
8
11
|
constructor(collator) {
|
|
9
12
|
this.#collator = collator;
|
|
10
13
|
}
|
|
@@ -48,6 +51,9 @@ class NamedExportManager {
|
|
|
48
51
|
}
|
|
49
52
|
class NamespaceExportManager extends StatementRecordManager {
|
|
50
53
|
#map = /* @__PURE__ */ new Map();
|
|
54
|
+
get size() {
|
|
55
|
+
return this.#map.size;
|
|
56
|
+
}
|
|
51
57
|
addCombined(path, name, uniqueId) {
|
|
52
58
|
const id = uniqueId ?? createFullyUniqueIdentifier(name);
|
|
53
59
|
this.#map.set(path, id);
|
|
@@ -90,6 +96,9 @@ class NamespaceExportManager extends StatementRecordManager {
|
|
|
90
96
|
}
|
|
91
97
|
class DefaultExportManager {
|
|
92
98
|
#id;
|
|
99
|
+
get isEmpty() {
|
|
100
|
+
return !this.#id;
|
|
101
|
+
}
|
|
93
102
|
set(id) {
|
|
94
103
|
this.#id = typeof id === "string" ? ts.factory.createIdentifier(id) : id;
|
|
95
104
|
return this.#id;
|
|
@@ -102,6 +111,9 @@ class ExportManager {
|
|
|
102
111
|
default = new DefaultExportManager();
|
|
103
112
|
named;
|
|
104
113
|
namespace;
|
|
114
|
+
get size() {
|
|
115
|
+
return (this.default.isEmpty ? 0 : 1) + this.named.size + this.namespace.size;
|
|
116
|
+
}
|
|
105
117
|
constructor(collator) {
|
|
106
118
|
this.named = new NamedExportManager(collator);
|
|
107
119
|
this.namespace = new NamespaceExportManager(collator);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/dependencies/ExportManager.ts"],
|
|
4
|
-
"sourcesContent": ["import ts, { type ExportAssignment, type ExportDeclaration, type Identifier, type Statement } from 'typescript';\nimport createFullyUniqueIdentifier from '../createFullyUniqueIdentifier.js';\nimport type CodeConvertable from './CodeConvertable.js';\nimport StatementRecordManager, { type StatementRecord } from './StatementRecordManager.js';\nimport { createDependencyRecord, type DependencyRecord } from './utils.js';\n\nexport class NamedExportManager implements CodeConvertable<ExportDeclaration | undefined> {\n readonly #collator: Intl.Collator;\n readonly #map = new Map<string, DependencyRecord>();\n\n constructor(collator: Intl.Collator) {\n this.#collator = collator;\n }\n\n add(name: string, isType?: boolean, uniqueId?: Identifier): Identifier {\n const id = uniqueId ?? createFullyUniqueIdentifier(name);\n this.#map.set(name, createDependencyRecord(id, isType));\n return id;\n }\n\n getIdentifier(name: string): Identifier | undefined {\n return this.#map.get(name)?.id;\n }\n\n *identifiers(): IterableIterator<readonly [id: Identifier, isType: boolean]> {\n for (const { id, isType } of this.#map.values()) {\n yield [id, isType];\n }\n }\n\n isType(name: string): boolean | undefined {\n return this.#map.get(name)?.isType;\n }\n\n names(): IterableIterator<string> {\n return this.#map.keys();\n }\n\n toCode(): ExportDeclaration | undefined {\n if (this.#map.size === 0) {\n return undefined;\n }\n\n const names = [...this.#map.keys()];\n // eslint-disable-next-line @typescript-eslint/unbound-method\n names.sort(this.#collator.compare);\n\n return ts.factory.createExportDeclaration(\n undefined,\n false,\n ts.factory.createNamedExports(\n names.map((name) => {\n const { id, isType } = this.#map.get(name)!;\n return ts.factory.createExportSpecifier(isType, id, ts.factory.createIdentifier(name));\n }),\n ),\n undefined,\n );\n }\n}\n\nexport class NamespaceExportManager extends StatementRecordManager<ExportDeclaration> {\n readonly #map = new Map<string, Identifier | null>();\n\n addCombined(path: string, name: string, uniqueId?: Identifier): Identifier {\n const id = uniqueId ?? createFullyUniqueIdentifier(name);\n this.#map.set(path, id);\n return id;\n }\n\n addSpread(path: string): void {\n this.#map.set(path, null);\n }\n\n override clear(): void {\n this.#map.clear();\n }\n\n getIdentifier(path: string): Identifier | null | undefined {\n return this.#map.get(path);\n }\n\n identifiers(): IterableIterator<Identifier | null> {\n return this.#map.values();\n }\n\n isCombined(path: string): boolean | undefined {\n return this.#map.has(path) ? this.#map.get(path) !== null : undefined;\n }\n\n isSpread(path: string): boolean | undefined {\n return this.#map.has(path) ? this.#map.get(path) === null : undefined;\n }\n\n paths(): IterableIterator<string> {\n return this.#map.keys();\n }\n\n override *statementRecords(): IterableIterator<StatementRecord<ExportDeclaration>> {\n for (const [path, id] of this.#map) {\n yield [\n path,\n ts.factory.createExportDeclaration(\n undefined,\n false,\n id !== null ? ts.factory.createNamespaceExport(id) : undefined,\n ts.factory.createStringLiteral(path),\n ),\n ];\n }\n }\n}\n\nexport class DefaultExportManager implements CodeConvertable<ExportAssignment | undefined> {\n #id?: Identifier;\n\n set(id: Identifier | string): Identifier {\n this.#id = typeof id === 'string' ? ts.factory.createIdentifier(id) : id;\n return this.#id;\n }\n\n toCode(): ExportAssignment | undefined {\n return this.#id ? ts.factory.createExportAssignment(undefined, undefined, this.#id) : undefined;\n }\n}\n\nexport default class ExportManager implements CodeConvertable<readonly Statement[]> {\n readonly default = new DefaultExportManager();\n readonly named: NamedExportManager;\n readonly namespace: NamespaceExportManager;\n\n constructor(collator: Intl.Collator) {\n this.named = new NamedExportManager(collator);\n this.namespace = new NamespaceExportManager(collator);\n }\n\n toCode(): readonly Statement[] {\n const defaultStatement = this.default.toCode();\n const namedStatement = this.named.toCode();\n const namespaceStatements = this.namespace.toCode();\n\n const result: Statement[] = [];\n\n if (namedStatement) {\n result.push(namedStatement);\n }\n\n result.push(...namespaceStatements);\n\n if (defaultStatement) {\n result.push(defaultStatement);\n }\n\n return result;\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,OAAO,YAA4F;AACnG,OAAO,iCAAiC;AAExC,OAAO,gCAAsD;AAC7D,SAAS,8BAAqD;AAEvD,MAAM,mBAA6E;AAAA,EAC/E;AAAA,EACA,OAAO,oBAAI,IAA8B;AAAA,EAElD,YAAY,UAAyB;AACnC,SAAK,YAAY;AAAA,EACnB;AAAA,EAEA,IAAI,MAAc,QAAkB,UAAmC;AACrE,UAAM,KAAK,YAAY,4BAA4B,IAAI;AACvD,SAAK,KAAK,IAAI,MAAM,uBAAuB,IAAI,MAAM,CAAC;AACtD,WAAO;AAAA,EACT;AAAA,EAEA,cAAc,MAAsC;AAClD,WAAO,KAAK,KAAK,IAAI,IAAI,GAAG;AAAA,EAC9B;AAAA,EAEA,CAAC,cAA4E;AAC3E,eAAW,EAAE,IAAI,OAAO,KAAK,KAAK,KAAK,OAAO,GAAG;AAC/C,YAAM,CAAC,IAAI,MAAM;AAAA,IACnB;AAAA,EACF;AAAA,EAEA,OAAO,MAAmC;AACxC,WAAO,KAAK,KAAK,IAAI,IAAI,GAAG;AAAA,EAC9B;AAAA,EAEA,QAAkC;AAChC,WAAO,KAAK,KAAK,KAAK;AAAA,EACxB;AAAA,EAEA,SAAwC;AACtC,QAAI,KAAK,KAAK,SAAS,GAAG;AACxB,aAAO;AAAA,IACT;AAEA,UAAM,QAAQ,CAAC,GAAG,KAAK,KAAK,KAAK,CAAC;AAElC,UAAM,KAAK,KAAK,UAAU,OAAO;AAEjC,WAAO,GAAG,QAAQ;AAAA,MAChB;AAAA,MACA;AAAA,MACA,GAAG,QAAQ;AAAA,QACT,MAAM,IAAI,CAAC,SAAS;AAClB,gBAAM,EAAE,IAAI,OAAO,IAAI,KAAK,KAAK,IAAI,IAAI;AACzC,iBAAO,GAAG,QAAQ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;AACvC,SAAK,MAAM,OAAO,OAAO,WAAW,GAAG,QAAQ,iBAAiB,EAAE,IAAI;AACtE,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,SAAuC;AACrC,WAAO,KAAK,MAAM,GAAG,QAAQ,uBAAuB,QAAW,QAAW,KAAK,GAAG,IAAI;AAAA,EACxF;AACF;AAEA,MAAO,cAA6E;AAAA,EACzE,UAAU,IAAI,qBAAqB;AAAA,EACnC;AAAA,EACA;AAAA,EAET,YAAY,UAAyB;AACnC,SAAK,QAAQ,IAAI,mBAAmB,QAAQ;AAC5C,SAAK,YAAY,IAAI,uBAAuB,QAAQ;AAAA,EACtD;AAAA,EAEA,SAA+B;AAC7B,UAAM,mBAAmB,KAAK,QAAQ,OAAO;AAC7C,UAAM,iBAAiB,KAAK,MAAM,OAAO;AACzC,UAAM,sBAAsB,KAAK,UAAU,OAAO;AAElD,UAAM,SAAsB,CAAC;AAE7B,QAAI,gBAAgB;AAClB,aAAO,KAAK,cAAc;AAAA,IAC5B;AAEA,WAAO,KAAK,GAAG,mBAAmB;AAElC,QAAI,kBAAkB;AACpB,aAAO,KAAK,gBAAgB;AAAA,IAC9B;AAEA,WAAO;AAAA,EACT;AACF;",
|
|
4
|
+
"sourcesContent": ["import ts, { type ExportAssignment, type ExportDeclaration, type Identifier, type Statement } from 'typescript';\nimport createFullyUniqueIdentifier from '../createFullyUniqueIdentifier.js';\nimport type CodeConvertable from './CodeConvertable.js';\nimport StatementRecordManager, { type StatementRecord } from './StatementRecordManager.js';\nimport { createDependencyRecord, type DependencyRecord } from './utils.js';\n\nexport class NamedExportManager implements CodeConvertable<ExportDeclaration | undefined> {\n readonly #collator: Intl.Collator;\n readonly #map = new Map<string, DependencyRecord>();\n\n get size(): number {\n return this.#map.size;\n }\n\n constructor(collator: Intl.Collator) {\n this.#collator = collator;\n }\n\n add(name: string, isType?: boolean, uniqueId?: Identifier): Identifier {\n const id = uniqueId ?? createFullyUniqueIdentifier(name);\n this.#map.set(name, createDependencyRecord(id, isType));\n return id;\n }\n\n getIdentifier(name: string): Identifier | undefined {\n return this.#map.get(name)?.id;\n }\n\n *identifiers(): IterableIterator<readonly [id: Identifier, isType: boolean]> {\n for (const { id, isType } of this.#map.values()) {\n yield [id, isType];\n }\n }\n\n isType(name: string): boolean | undefined {\n return this.#map.get(name)?.isType;\n }\n\n names(): IterableIterator<string> {\n return this.#map.keys();\n }\n\n toCode(): ExportDeclaration | undefined {\n if (this.#map.size === 0) {\n return undefined;\n }\n\n const names = [...this.#map.keys()];\n // eslint-disable-next-line @typescript-eslint/unbound-method\n names.sort(this.#collator.compare);\n\n return ts.factory.createExportDeclaration(\n undefined,\n false,\n ts.factory.createNamedExports(\n names.map((name) => {\n const { id, isType } = this.#map.get(name)!;\n return ts.factory.createExportSpecifier(isType, id, ts.factory.createIdentifier(name));\n }),\n ),\n undefined,\n );\n }\n}\n\nexport class NamespaceExportManager extends StatementRecordManager<ExportDeclaration> {\n readonly #map = new Map<string, Identifier | null>();\n\n get size(): number {\n return this.#map.size;\n }\n\n addCombined(path: string, name: string, uniqueId?: Identifier): Identifier {\n const id = uniqueId ?? createFullyUniqueIdentifier(name);\n this.#map.set(path, id);\n return id;\n }\n\n addSpread(path: string): void {\n this.#map.set(path, null);\n }\n\n override clear(): void {\n this.#map.clear();\n }\n\n getIdentifier(path: string): Identifier | null | undefined {\n return this.#map.get(path);\n }\n\n identifiers(): IterableIterator<Identifier | null> {\n return this.#map.values();\n }\n\n isCombined(path: string): boolean | undefined {\n return this.#map.has(path) ? this.#map.get(path) !== null : undefined;\n }\n\n isSpread(path: string): boolean | undefined {\n return this.#map.has(path) ? this.#map.get(path) === null : undefined;\n }\n\n paths(): IterableIterator<string> {\n return this.#map.keys();\n }\n\n override *statementRecords(): IterableIterator<StatementRecord<ExportDeclaration>> {\n for (const [path, id] of this.#map) {\n yield [\n path,\n ts.factory.createExportDeclaration(\n undefined,\n false,\n id !== null ? ts.factory.createNamespaceExport(id) : undefined,\n ts.factory.createStringLiteral(path),\n ),\n ];\n }\n }\n}\n\nexport class DefaultExportManager implements CodeConvertable<ExportAssignment | undefined> {\n #id?: Identifier;\n\n get isEmpty(): boolean {\n return !this.#id;\n }\n\n set(id: Identifier | string): Identifier {\n this.#id = typeof id === 'string' ? ts.factory.createIdentifier(id) : id;\n return this.#id;\n }\n\n toCode(): ExportAssignment | undefined {\n return this.#id ? ts.factory.createExportAssignment(undefined, undefined, this.#id) : undefined;\n }\n}\n\nexport default class ExportManager implements CodeConvertable<readonly Statement[]> {\n readonly default = new DefaultExportManager();\n readonly named: NamedExportManager;\n readonly namespace: NamespaceExportManager;\n\n get size(): number {\n return (this.default.isEmpty ? 0 : 1) + this.named.size + this.namespace.size;\n }\n\n constructor(collator: Intl.Collator) {\n this.named = new NamedExportManager(collator);\n this.namespace = new NamespaceExportManager(collator);\n }\n\n toCode(): readonly Statement[] {\n const defaultStatement = this.default.toCode();\n const namedStatement = this.named.toCode();\n const namespaceStatements = this.namespace.toCode();\n\n const result: Statement[] = [];\n\n if (namedStatement) {\n result.push(namedStatement);\n }\n\n result.push(...namespaceStatements);\n\n if (defaultStatement) {\n result.push(defaultStatement);\n }\n\n return result;\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,YAA4F;AACnG,OAAO,iCAAiC;AAExC,OAAO,gCAAsD;AAC7D,SAAS,8BAAqD;AAEvD,MAAM,mBAA6E;AAAA,EAC/E;AAAA,EACA,OAAO,oBAAI,IAA8B;AAAA,EAElD,IAAI,OAAe;AACjB,WAAO,KAAK,KAAK;AAAA,EACnB;AAAA,EAEA,YAAY,UAAyB;AACnC,SAAK,YAAY;AAAA,EACnB;AAAA,EAEA,IAAI,MAAc,QAAkB,UAAmC;AACrE,UAAM,KAAK,YAAY,4BAA4B,IAAI;AACvD,SAAK,KAAK,IAAI,MAAM,uBAAuB,IAAI,MAAM,CAAC;AACtD,WAAO;AAAA,EACT;AAAA,EAEA,cAAc,MAAsC;AAClD,WAAO,KAAK,KAAK,IAA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Q,IAAI,mBAAmB,QAAQ;AAC5C,SAAK,YAAY,IAAI,uBAAuB,QAAQ;AAAA,EACtD;AAAA,EAEA,SAA+B;AAC7B,UAAM,mBAAmB,KAAK,QAAQ,OAAO;AAC7C,UAAM,iBAAiB,KAAK,MAAM,OAAO;AACzC,UAAM,sBAAsB,KAAK,UAAU,OAAO;AAElD,UAAM,SAAsB,CAAC;AAE7B,QAAI,gBAAgB;AAClB,aAAO,KAAK,cAAc;AAAA,IAC5B;AAEA,WAAO,KAAK,GAAG,mBAAmB;AAElC,QAAI,kBAAkB;AACpB,aAAO,KAAK,gBAAgB;AAAA,IAC9B;AAEA,WAAO;AAAA,EACT;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -4,6 +4,7 @@ import StatementRecordManager, { type StatementRecord } from './StatementRecordM
|
|
|
4
4
|
export declare class NamedImportManager extends StatementRecordManager<ImportDeclaration> {
|
|
5
5
|
#private;
|
|
6
6
|
constructor(collator: Intl.Collator);
|
|
7
|
+
get size(): number;
|
|
7
8
|
add(path: string, specifier: string, isType?: boolean, uniqueId?: Identifier): Identifier;
|
|
8
9
|
remove(path: string, specifier: string): void;
|
|
9
10
|
clear(): void;
|
|
@@ -17,6 +18,7 @@ export declare class NamedImportManager extends StatementRecordManager<ImportDec
|
|
|
17
18
|
}
|
|
18
19
|
export declare class NamespaceImportManager extends StatementRecordManager<ImportDeclaration> {
|
|
19
20
|
#private;
|
|
21
|
+
get size(): number;
|
|
20
22
|
add(path: string, name: string, uniqueId?: Identifier): Identifier;
|
|
21
23
|
clear(): void;
|
|
22
24
|
getIdentifier(path: string): Identifier | undefined;
|
|
@@ -28,6 +30,7 @@ export declare class NamespaceImportManager extends StatementRecordManager<Impor
|
|
|
28
30
|
}
|
|
29
31
|
export declare class DefaultImportManager extends StatementRecordManager<ImportDeclaration> {
|
|
30
32
|
#private;
|
|
33
|
+
get size(): number;
|
|
31
34
|
add(path: string, name: string, isType?: boolean, uniqueId?: Identifier): Identifier;
|
|
32
35
|
getIdentifier(path: string): Identifier | undefined;
|
|
33
36
|
remove(path: string): void;
|
|
@@ -44,6 +47,7 @@ export default class ImportManager implements CodeConvertable<readonly Statement
|
|
|
44
47
|
readonly named: NamedImportManager;
|
|
45
48
|
readonly namespace: NamespaceImportManager;
|
|
46
49
|
constructor(collator: Intl.Collator);
|
|
50
|
+
get size(): number;
|
|
47
51
|
toCode(): readonly Statement[];
|
|
48
52
|
fromCode(source: ts.SourceFile): void;
|
|
49
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImportManager.d.ts","sourceRoot":"","sources":["../src/dependencies/ImportManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,KAAK,UAAU,EAAE,KAAK,iBAAiB,EAAE,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAEzF,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAC;AACxD,OAAO,sBAAsB,EAAE,EAAE,KAAK,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAG3F,qBAAa,kBAAmB,SAAQ,sBAAsB,CAAC,iBAAiB,CAAC;;gBAInE,QAAQ,EAAE,IAAI,CAAC,QAAQ;IAKnC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,UAAU,GAAG,UAAU;IAYzF,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;IAYpC,KAAK,IAAI,IAAI;IAItB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAItE,IAAI,IAAI,gBAAgB,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAIrG,MAAM,CAAC,IA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|
13
|
+
return this.#map.size;
|
|
14
|
+
}
|
|
12
15
|
add(path, specifier, isType, uniqueId) {
|
|
13
16
|
const record = createDependencyRecord(uniqueId ?? createFullyUniqueIdentifier(specifier), isType);
|
|
14
17
|
if (this.#map.has(path)) {
|
|
@@ -53,17 +56,22 @@ class NamedImportManager extends StatementRecordManager {
|
|
|
53
56
|
for (const [path, specifiers] of this.#map) {
|
|
54
57
|
const names = [...specifiers.keys()];
|
|
55
58
|
names.sort(this.#collator.compare);
|
|
59
|
+
const isTypeOnly = names.every((name) => specifiers.get(name).isType);
|
|
56
60
|
yield [
|
|
57
61
|
path,
|
|
58
62
|
ts.factory.createImportDeclaration(
|
|
59
63
|
void 0,
|
|
60
64
|
ts.factory.createImportClause(
|
|
61
|
-
|
|
65
|
+
isTypeOnly,
|
|
62
66
|
void 0,
|
|
63
67
|
ts.factory.createNamedImports(
|
|
64
68
|
names.map((name) => {
|
|
65
69
|
const { id, isType } = specifiers.get(name);
|
|
66
|
-
return ts.factory.createImportSpecifier(
|
|
70
|
+
return ts.factory.createImportSpecifier(
|
|
71
|
+
isTypeOnly ? false : isType,
|
|
72
|
+
ts.factory.createIdentifier(name),
|
|
73
|
+
id
|
|
74
|
+
);
|
|
67
75
|
})
|
|
68
76
|
)
|
|
69
77
|
),
|
|
@@ -82,6 +90,9 @@ class NamedImportManager extends StatementRecordManager {
|
|
|
82
90
|
}
|
|
83
91
|
class NamespaceImportManager extends StatementRecordManager {
|
|
84
92
|
#map = /* @__PURE__ */ new Map();
|
|
93
|
+
get size() {
|
|
94
|
+
return this.#map.size;
|
|
95
|
+
}
|
|
85
96
|
add(path, name, uniqueId) {
|
|
86
97
|
const id = uniqueId ?? createFullyUniqueIdentifier(name);
|
|
87
98
|
this.#map.set(path, id);
|
|
@@ -122,6 +133,9 @@ class NamespaceImportManager extends StatementRecordManager {
|
|
|
122
133
|
}
|
|
123
134
|
class DefaultImportManager extends StatementRecordManager {
|
|
124
135
|
#map = /* @__PURE__ */ new Map();
|
|
136
|
+
get size() {
|
|
137
|
+
return this.#map.size;
|
|
138
|
+
}
|
|
125
139
|
add(path, name, isType, uniqueId) {
|
|
126
140
|
const id = uniqueId ?? createFullyUniqueIdentifier(name);
|
|
127
141
|
this.#map.set(path, createDependencyRecord(id, isType));
|
|
@@ -176,6 +190,9 @@ class ImportManager {
|
|
|
176
190
|
this.namespace = new NamespaceImportManager(collator);
|
|
177
191
|
this.#collator = collator;
|
|
178
192
|
}
|
|
193
|
+
get size() {
|
|
194
|
+
return this.default.size + this.named.size + this.namespace.size;
|
|
195
|
+
}
|
|
179
196
|
toCode() {
|
|
180
197
|
const records = [
|
|
181
198
|
...this.default.statementRecords(),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/dependencies/ImportManager.ts"],
|
|
4
|
-
"sourcesContent": ["import ts, { type Identifier, type ImportDeclaration, type Statement } from 'typescript';\nimport createFullyUniqueIdentifier from '../createFullyUniqueIdentifier.js';\nimport type CodeConvertable from './CodeConvertable.js';\nimport StatementRecordManager, { type StatementRecord } from './StatementRecordManager.js';\nimport { createDependencyRecord, type DependencyRecord } from './utils.js';\n\nexport class NamedImportManager extends StatementRecordManager<ImportDeclaration> {\n readonly #collator: Intl.Collator;\n readonly #map = new Map<string, Map<string, DependencyRecord>>();\n\n constructor(collator: Intl.Collator) {\n super(collator);\n this.#collator = collator;\n }\n\n add(path: string, specifier: string, isType?: boolean, uniqueId?: Identifier): Identifier {\n const record = createDependencyRecord(uniqueId ?? createFullyUniqueIdentifier(specifier), isType);\n\n if (this.#map.has(path)) {\n this.#map.get(path)!.set(specifier, record);\n } else {\n this.#map.set(path, new Map([[specifier, record]]));\n }\n\n return record.id;\n }\n\n remove(path: string, specifier: string): void {\n const specifiers = this.#map.get(path);\n\n if (specifiers) {\n specifiers.delete(specifier);\n\n if (specifiers.size === 0) {\n this.#map.delete(path);\n }\n }\n }\n\n override clear(): void {\n this.#map.clear();\n }\n\n getIdentifier(path: string, specifier: string): Identifier | undefined {\n return this.#map.get(path)?.get(specifier)?.id;\n }\n\n iter(): IterableIterator<readonly [path: string, specifier: string, id: Identifier, isType: boolean]> {\n return this[Symbol.iterator]();\n }\n\n isType(path: string, specifier: string): boolean | undefined {\n return this.#map.get(path)?.get(specifier)?.isType;\n }\n\n paths(): IterableIterator<string> {\n return this.#map.keys();\n }\n\n *specifiers(): IterableIterator<readonly [path: string, specifier: string]> {\n for (const [path, specifiers] of this.#map) {\n for (const specifier of specifiers.keys()) {\n yield [path, specifier];\n }\n }\n }\n\n override *statementRecords(): IterableIterator<StatementRecord<ImportDeclaration>> {\n for (const [path, specifiers] of this.#map) {\n const names = [...specifiers.keys()];\n // eslint-disable-next-line @typescript-eslint/unbound-method\n names.sort(this.#collator.compare);\n\n yield [\n path,\n ts.factory.createImportDeclaration(\n undefined,\n ts.factory.createImportClause(\n
|
|
5
|
-
"mappings": "AAAA,OAAO,YAAqE;AAC5E,OAAO,iCAAiC;AAExC,OAAO,gCAAsD;AAC7D,SAAS,8BAAqD;AAEvD,MAAM,2BAA2B,uBAA0C;AAAA,EACvE;AAAA,EACA,OAAO,oBAAI,IAA2C;AAAA,EAE/D,YAAY,UAAyB;AACnC,UAAM,QAAQ;AACd,SAAK,YAAY;AAAA,EACnB;AAAA,EAEA,IAAI,MAAc,WAAmB,QAAkB,UAAmC;AACxF,UAAM,SAAS,uBAAuB,YAAY,4BAA4B,SAAS,GAAG,MAAM;AAEhG,QAAI,KAAK,KAAK,IAAI,IAAI,GAAG;AACvB,WAAK,KAAK,IAAI,IAAI,EAAG,IAAI,WAAW,MAAM;AAAA,IAC5C,OAAO;AACL,WAAK,KAAK,IAAI,MAAM,oBAAI,IAAI,CAAC,CAAC,WAAW,MAAM,CAAC,CAAC,CAAC;AAAA,IACpD;AAEA,WAAO,OAAO;AAAA,EAChB;AAAA,EAEA,OAAO,MAAc,WAAyB;AAC5C,UAAM,aAAa,KAAK,KAAK,IAAI,IAAI;AAErC,QAAI,YAAY;AACd,iBAAW,OAAO,SAAS;AAE3B,UAAI,WAAW,SAAS,GAAG;AACzB,aAAK,KAAK,OAAO,IAAI;AAAA,MACvB;AAAA,IACF;AAAA,EACF;AAAA,EAES,QAAc;AACrB,SAAK,KAAK,MAAM;AAAA,EAClB;AAAA,EAEA,cAAc,MAAc,WAA2C;AACrE,WAAO,KAAK,KAAK,IAAI,IAAI,GAAG,IAAI,SAAS,GAAG;AAAA,EAC9C;AAAA,EAEA,OAAsG;AACpG,WAAO,KAAK,OAAO,QAAQ,EAAE;AAAA,EAC/B;AAAA,EAEA,OAAO,MAAc,WAAwC;AAC3D,WAAO,KAAK,KAAK,IAAI,IAAI,GAAG,IAAI,SAAS,GAAG;AAAA,EAC9C;AAAA,EAEA,QAAkC;AAChC,WAAO,KAAK,KAAK,KAAK;AAAA,EACxB;AAAA,EAEA,CAAC,aAA2E;AAC1E,eAAW,CAAC,MAAM,UAAU,KAAK,KAAK,MAAM;AAC1C,iBAAW,aAAa,WAAW,KAAK,GAAG;AACzC,cAAM,CAAC,MAAM,SAAS;AAAA,MACxB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,CAAU,mBAAyE;AACjF,eAAW,CAAC,MAAM,UAAU,KAAK,KAAK,MAAM;AAC1C,YAAM,QAAQ,CAAC,GAAG,WAAW,KAAK,CAAC;AAEnC,YAAM,KAAK,KAAK,UAAU,OAAO;AAEjC,YAAM;AAAA,QACJ;AAAA,QACA,GAAG,QAAQ;AAAA,UACT;AAAA,UACA,GAAG,QAAQ;AAAA,YACT;AAAA,YACA;AAAA,YACA,GAAG,QAAQ;AAAA,cACT,MAAM,IAAI,CAAC,SAAS;AAClB,sBAAM,EAAE,IAAI,OAAO,IAAI,WAAW,IAAI,IAAI;AAC1C,uBAAO,GAAG,QAAQ,
|
|
4
|
+
"sourcesContent": ["import ts, { type Identifier, type ImportDeclaration, type Statement } from 'typescript';\nimport createFullyUniqueIdentifier from '../createFullyUniqueIdentifier.js';\nimport type CodeConvertable from './CodeConvertable.js';\nimport StatementRecordManager, { type StatementRecord } from './StatementRecordManager.js';\nimport { createDependencyRecord, type DependencyRecord } from './utils.js';\n\nexport class NamedImportManager extends StatementRecordManager<ImportDeclaration> {\n readonly #collator: Intl.Collator;\n readonly #map = new Map<string, Map<string, DependencyRecord>>();\n\n constructor(collator: Intl.Collator) {\n super(collator);\n this.#collator = collator;\n }\n\n get size(): number {\n return this.#map.size;\n }\n\n add(path: string, specifier: string, isType?: boolean, uniqueId?: Identifier): Identifier {\n const record = createDependencyRecord(uniqueId ?? createFullyUniqueIdentifier(specifier), isType);\n\n if (this.#map.has(path)) {\n this.#map.get(path)!.set(specifier, record);\n } else {\n this.#map.set(path, new Map([[specifier, record]]));\n }\n\n return record.id;\n }\n\n remove(path: string, specifier: string): void {\n const specifiers = this.#map.get(path);\n\n if (specifiers) {\n specifiers.delete(specifier);\n\n if (specifiers.size === 0) {\n this.#map.delete(path);\n }\n }\n }\n\n override clear(): void {\n this.#map.clear();\n }\n\n getIdentifier(path: string, specifier: string): Identifier | undefined {\n return this.#map.get(path)?.get(specifier)?.id;\n }\n\n iter(): IterableIterator<readonly [path: string, specifier: string, id: Identifier, isType: boolean]> {\n return this[Symbol.iterator]();\n }\n\n isType(path: string, specifier: string): boolean | undefined {\n return this.#map.get(path)?.get(specifier)?.isType;\n }\n\n paths(): IterableIterator<string> {\n return this.#map.keys();\n }\n\n *specifiers(): IterableIterator<readonly [path: string, specifier: string]> {\n for (const [path, specifiers] of this.#map) {\n for (const specifier of specifiers.keys()) {\n yield [path, specifier];\n }\n }\n }\n\n override *statementRecords(): IterableIterator<StatementRecord<ImportDeclaration>> {\n for (const [path, specifiers] of this.#map) {\n const names = [...specifiers.keys()];\n // eslint-disable-next-line @typescript-eslint/unbound-method\n names.sort(this.#collator.compare);\n\n const isTypeOnly = names.every((name) => specifiers.get(name)!.isType);\n\n yield [\n path,\n ts.factory.createImportDeclaration(\n undefined,\n ts.factory.createImportClause(\n isTypeOnly,\n undefined,\n ts.factory.createNamedImports(\n names.map((name) => {\n const { id, isType } = specifiers.get(name)!;\n return ts.factory.createImportSpecifier(\n isTypeOnly ? false : isType,\n ts.factory.createIdentifier(name),\n id,\n );\n }),\n ),\n ),\n ts.factory.createStringLiteral(path),\n ),\n ];\n }\n }\n\n *[Symbol.iterator](): IterableIterator<readonly [path: string, specifier: string, id: Identifier, isType: boolean]> {\n for (const [path, specifiers] of this.#map) {\n for (const [specifier, { id, isType }] of specifiers) {\n yield [path, specifier, id, isType];\n }\n }\n }\n}\n\nexport class NamespaceImportManager extends StatementRecordManager<ImportDeclaration> {\n readonly #map = new Map<string, Identifier>();\n\n get size(): number {\n return this.#map.size;\n }\n\n add(path: string, name: string, uniqueId?: Identifier): Identifier {\n const id = uniqueId ?? createFullyUniqueIdentifier(name);\n this.#map.set(path, id);\n return id;\n }\n\n override clear(): void {\n this.#map.clear();\n }\n\n getIdentifier(path: string): Identifier | undefined {\n return this.#map.get(path);\n }\n\n iter(): IterableIterator<readonly [path: string, id: Identifier]> {\n return this[Symbol.iterator]();\n }\n\n paths(): IterableIterator<string> {\n return this.#map.keys();\n }\n\n override *statementRecords(): IterableIterator<StatementRecord<ImportDeclaration>> {\n for (const [path, id] of this.#map) {\n yield [\n path,\n ts.factory.createImportDeclaration(\n undefined,\n ts.factory.createImportClause(false, undefined, ts.factory.createNamespaceImport(id)),\n ts.factory.createStringLiteral(path),\n ),\n ];\n }\n }\n\n remove(path: string): void {\n this.#map.delete(path);\n }\n\n *[Symbol.iterator](): IterableIterator<readonly [path: string, id: Identifier]> {\n for (const [path, id] of this.#map) {\n yield [path, id];\n }\n }\n}\n\nexport class DefaultImportManager extends StatementRecordManager<ImportDeclaration> {\n readonly #map = new Map<string, DependencyRecord>();\n\n get size(): number {\n return this.#map.size;\n }\n\n add(path: string, name: string, isType?: boolean, uniqueId?: Identifier): Identifier {\n const id = uniqueId ?? createFullyUniqueIdentifier(name);\n this.#map.set(path, createDependencyRecord(id, isType));\n return id;\n }\n\n getIdentifier(path: string): Identifier | undefined {\n return this.#map.get(path)?.id;\n }\n\n remove(path: string): void {\n if (this.#map.has(path)) {\n this.#map.delete(path);\n }\n }\n\n override clear(): void {\n this.#map.clear();\n }\n\n iter(): IterableIterator<readonly [path: string, id: Identifier, isType: boolean]> {\n return this[Symbol.iterator]();\n }\n\n isType(path: string): boolean | undefined {\n return this.#map.get(path)?.isType;\n }\n\n paths(): IterableIterator<string> {\n return this.#map.keys();\n }\n\n override *statementRecords(): IterableIterator<StatementRecord<ImportDeclaration>> {\n for (const [path, { id, isType }] of this.#map) {\n yield [\n path,\n ts.factory.createImportDeclaration(\n undefined,\n ts.factory.createImportClause(isType, id, undefined),\n ts.factory.createStringLiteral(path),\n ),\n ];\n }\n }\n\n *[Symbol.iterator](): IterableIterator<readonly [path: string, id: Identifier, isType: boolean]> {\n for (const [path, { id, isType }] of this.#map) {\n yield [path, id, isType];\n }\n }\n}\n\nexport default class ImportManager implements CodeConvertable<readonly Statement[]> {\n readonly default: DefaultImportManager;\n readonly named: NamedImportManager;\n readonly namespace: NamespaceImportManager;\n\n readonly #collator: Intl.Collator;\n\n constructor(collator: Intl.Collator) {\n this.default = new DefaultImportManager(collator);\n this.named = new NamedImportManager(collator);\n this.namespace = new NamespaceImportManager(collator);\n this.#collator = collator;\n }\n\n get size(): number {\n return this.default.size + this.named.size + this.namespace.size;\n }\n\n toCode(): readonly Statement[] {\n const records = [\n ...this.default.statementRecords(),\n ...this.named.statementRecords(),\n ...this.namespace.statementRecords(),\n ];\n records.sort(StatementRecordManager.createComparator(this.#collator));\n\n return records.map(([, statement]) => statement);\n }\n\n fromCode(source: ts.SourceFile): void {\n this.default.clear();\n this.named.clear();\n this.namespace.clear();\n\n const imports = source.statements.filter((statement): statement is ImportDeclaration =>\n ts.isImportDeclaration(statement),\n );\n\n for (const { importClause, moduleSpecifier } of imports) {\n if (!importClause) {\n // eslint-disable-next-line no-continue\n continue;\n }\n\n const { name, namedBindings } = importClause;\n const path = (moduleSpecifier as ts.StringLiteral).text;\n\n if (namedBindings) {\n if (ts.isNamespaceImport(namedBindings)) {\n this.namespace.add(path, namedBindings.name.text, namedBindings.name);\n } else {\n for (const { isTypeOnly, name: specifier } of namedBindings.elements) {\n this.named.add(path, specifier.text, isTypeOnly, specifier);\n }\n }\n } else if (name) {\n this.default.add(path, name.text, importClause.isTypeOnly, name);\n }\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,YAAqE;AAC5E,OAAO,iCAAiC;AAExC,OAAO,gCAAsD;AAC7D,SAAS,8BAAqD;AAEvD,MAAM,2BAA2B,uBAA0C;AAAA,EACvE;AAAA,EACA,OAAO,oBAAI,IAA2C;AAAA,EAE/D,YAAY,UAAyB;AACnC,UAAM,QAAQ;AACd,SAAK,YAAY;AAAA,EACnB;AAAA,EAEA,IAAI,OAAe;AACjB,WAAO,KAAK,KAAK;AAAA,EACnB;AAAA,EAEA,IAAI,MAAc,WAAmB,QAAkB,UAAmC;AACxF,UAAM,SAAS,uBAAuB,YAAY,4BAA4B,SAAS,GAAG,MAAM;AAEhG,QAAI,KAAK,KAAK,IAAI,IAAI,GAAG;AACvB,WAAK,KAAK,IAAI,IAAI,EAAG,IAAI,WAAW,MAAM;AAAA,IAC5C,OAAO;AACL,WAAK,KAAK,IAAI,MAAM,oBAAI,IAAI,CAAC,CAAC,WAAW,MAAM,CAAC,CAAC,CAAC;AAAA,IACpD;AAEA,WAAO,OAAO;AAAA,EAChB;AAAA,EAEA,OAAO,MAAc,WAAyB;AAC5C,UAAM,aAAa,KAAK,KAAK,IAAI,IAAI;AAErC,QAAI,YAAY;AACd,iBAAW,OAAO,SAAS;AAE3B,UAAI,WAAW,SAAS,GAAG;AACzB,aAAK,KAAK,OAAO,IAAI;AAAA,MACvB;AAAA,IACF;AAAA,EACF;AAAA,EAES,QAAc;AACrB,SAAK,KAAK,MAAM;AAAA,EAClB;AAAA,EAEA,cAAc,MAAc,WAA2C;AACrE,WAA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AM,KAAK,MAAM,aAAa,YAAY,IAAI;AAAA,MACjE;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
export type PathManagerOptions = Readonly<{
|
|
2
2
|
aliasRoot?: string;
|
|
3
3
|
extension?: string;
|
|
4
|
-
relativeTo?: string;
|
|
4
|
+
relativeTo?: URL | string;
|
|
5
5
|
}>;
|
|
6
6
|
export default class PathManager {
|
|
7
7
|
#private;
|
|
8
8
|
constructor(options?: PathManagerOptions);
|
|
9
9
|
get aliasRoot(): string | undefined;
|
|
10
10
|
createBareModulePath(path: string, isFile?: boolean): string;
|
|
11
|
-
createRelativePath(path: string, relativeTo?: string): string;
|
|
11
|
+
createRelativePath(path: URL | string, fileExtension?: string, relativeTo?: string | URL): string;
|
|
12
12
|
createTSAliasModulePath(path: string, root?: string | undefined): string;
|
|
13
13
|
}
|
|
14
14
|
//# sourceMappingURL=PathManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PathManager.d.ts","sourceRoot":"","sources":["../src/dependencies/PathManager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PathManager.d.ts","sourceRoot":"","sources":["../src/dependencies/PathManager.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAC;IACxC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,GAAG,GAAG,MAAM,CAAC;CAC3B,CAAC,CAAC;AAEH,MAAM,CAAC,OAAO,OAAO,WAAW;;gBAGlB,OAAO,CAAC,EAAE,kBAAkB;IAcxC,IAAI,SAAS,IAAI,MAAM,GAAG,SAAS,CAElC;IAED,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,UAAQ,GAAG,MAAM;IAU1D,kBAAkB,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,EAAE,UAAU,eAA2B,GAAG,MAAM;IAgB7G,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,qBAA0B,GAAG,MAAM;CAG9E"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { posix } from "path";
|
|
1
|
+
import { basename, dirname, posix, relative, sep } from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
2
3
|
class PathManager {
|
|
3
4
|
#options;
|
|
4
5
|
constructor(options) {
|
|
@@ -22,13 +23,17 @@ class PathManager {
|
|
|
22
23
|
}
|
|
23
24
|
return path;
|
|
24
25
|
}
|
|
25
|
-
createRelativePath(path, relativeTo = this.#options.relativeTo) {
|
|
26
|
+
createRelativePath(path, fileExtension, relativeTo = this.#options.relativeTo) {
|
|
26
27
|
const { extension } = this.#options;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
const _path = path instanceof URL ? fileURLToPath(path) : path;
|
|
29
|
+
let result = _path;
|
|
30
|
+
if (extension && !_path.endsWith(extension)) {
|
|
31
|
+
result = `${dirname(result)}/${basename(result, fileExtension)}${extension}`;
|
|
30
32
|
}
|
|
31
|
-
result =
|
|
33
|
+
result = relative(relativeTo instanceof URL ? fileURLToPath(relativeTo) : relativeTo, result).replaceAll(
|
|
34
|
+
sep,
|
|
35
|
+
posix.sep
|
|
36
|
+
);
|
|
32
37
|
return result.startsWith(".") ? result : `./${result}`;
|
|
33
38
|
}
|
|
34
39
|
createTSAliasModulePath(path, root = this.#options.aliasRoot) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/dependencies/PathManager.ts"],
|
|
4
|
-
"sourcesContent": ["import { posix } from 'path';\nimport type { SetRequired } from 'type-fest';\n\nexport type PathManagerOptions = Readonly<{\n aliasRoot?: string;\n extension?: string;\n relativeTo?: string;\n}>;\n\nexport default class PathManager {\n readonly #options: SetRequired<PathManagerOptions, 'relativeTo'>;\n\n constructor(options?: PathManagerOptions) {\n let extension: string | undefined;\n\n if (options?.extension) {\n extension = options.extension.startsWith('.') ? options.extension : `.${options.extension}`;\n }\n\n this.#options = {\n ...options,\n extension,\n relativeTo: options?.relativeTo ?? '.',\n };\n }\n\n get aliasRoot(): string | undefined {\n return this.#options.aliasRoot;\n }\n\n createBareModulePath(path: string, isFile = false): string {\n const { extension } = this.#options;\n\n if (extension && isFile) {\n return `${path}.${extension}`;\n }\n\n return path;\n }\n\n createRelativePath(path: string, relativeTo = this.#options.relativeTo): string {\n const { extension } = this.#options;\n let result =
|
|
5
|
-
"mappings": "AAAA,SAAS,
|
|
4
|
+
"sourcesContent": ["import { basename, dirname, posix, relative, sep } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport type { SetRequired } from 'type-fest';\n\nexport type PathManagerOptions = Readonly<{\n aliasRoot?: string;\n extension?: string;\n relativeTo?: URL | string;\n}>;\n\nexport default class PathManager {\n readonly #options: SetRequired<PathManagerOptions, 'relativeTo'>;\n\n constructor(options?: PathManagerOptions) {\n let extension: string | undefined;\n\n if (options?.extension) {\n extension = options.extension.startsWith('.') ? options.extension : `.${options.extension}`;\n }\n\n this.#options = {\n ...options,\n extension,\n relativeTo: options?.relativeTo ?? '.',\n };\n }\n\n get aliasRoot(): string | undefined {\n return this.#options.aliasRoot;\n }\n\n createBareModulePath(path: string, isFile = false): string {\n const { extension } = this.#options;\n\n if (extension && isFile) {\n return `${path}.${extension}`;\n }\n\n return path;\n }\n\n createRelativePath(path: URL | string, fileExtension?: string, relativeTo = this.#options.relativeTo): string {\n const { extension } = this.#options;\n const _path = path instanceof URL ? fileURLToPath(path) : path;\n let result = _path;\n\n if (extension && !_path.endsWith(extension)) {\n result = `${dirname(result)}/${basename(result, fileExtension)}${extension}`;\n }\n\n result = relative(relativeTo instanceof URL ? fileURLToPath(relativeTo) : relativeTo, result).replaceAll(\n sep,\n posix.sep,\n );\n return result.startsWith('.') ? result : `./${result}`;\n }\n\n createTSAliasModulePath(path: string, root = this.#options.aliasRoot): string {\n return root ? `${root}/${path}` : path;\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,UAAU,SAAS,OAAO,UAAU,WAAW;AACxD,SAAS,qBAAqB;AAS9B,MAAO,YAA0B;AAAA,EACtB;AAAA,EAET,YAAY,SAA8B;AACxC,QAAI;AAEJ,QAAI,SAAS,WAAW;AACtB,kBAAY,QAAQ,UAAU,WAAW,GAAG,IAAI,QAAQ,YAAY,IAAI,QAAQ,SAAS;AAAA,IAC3F;AAEA,SAAK,WAAW;AAAA,MACd,GAAG;AAAA,MACH;AAAA,MACA,YAAY,SAAS,cAAc;AAAA,IACrC;AAAA,EACF;AAAA,EAEA,IAAI,YAAgC;AAClC,WAAO,KAAK,SAAS;AAAA,EACvB;AAAA,EAEA,qBAAqB,MAAc,SAAS,OAAe;AACzD,UAAM,EAAE,UAAU,IAAI,KAAK;AAE3B,QAAI,aAAa,QAAQ;AACvB,aAAO,GAAG,IAAI,IAAI,SAAS;AAAA,IAC7B;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,mBAAmB,MAAoB,eAAwB,aAAa,KAAK,SAAS,YAAoB;AAC5G,UAAM,EAAE,UAAU,IAAI,KAAK;AAC3B,UAAM,QAAQ,gBAAgB,MAAM,cAAc,IAAI,IAAI;AAC1D,QAAI,SAAS;AAEb,QAAI,aAAa,CAAC,MAAM,SAAS,SAAS,GAAG;AAC3C,eAAS,GAAG,QAAQ,MAAM,CAAC,IAAI,SAAS,QAAQ,aAAa,CAAC,GAAG,SAAS;AAAA,IAC5E;AAEA,aAAS,SAAS,sBAAsB,MAAM,cAAc,UAAU,IAAI,YAAY,MAAM,EAAE;AAAA,MAC5F;AAAA,MACA,MAAM;AAAA,IACR;AACA,WAAO,OAAO,WAAW,GAAG,IAAI,SAAS,KAAK,MAAM;AAAA,EACtD;AAAA,EAEA,wBAAwB,MAAc,OAAO,KAAK,SAAS,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