smartbundle 0.13.0-alpha.0 → 0.13.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/__compiled__/cjs/src/detectModules.js +7 -2
- package/__compiled__/cjs/src/detectModules.js.map +1 -1
- package/__compiled__/cjs/src/tasks/buildTypesTask/buildTypesTask.js +5 -0
- package/__compiled__/cjs/src/tasks/buildTypesTask/buildTypesTask.js.map +1 -1
- package/__compiled__/esm/src/detectModules.mjs +7 -2
- package/__compiled__/esm/src/detectModules.mjs.map +1 -1
- package/__compiled__/esm/src/tasks/buildTypesTask/buildTypesTask.mjs +5 -0
- package/__compiled__/esm/src/tasks/buildTypesTask/buildTypesTask.mjs.map +1 -1
- package/package.json +1 -1
@@ -84,7 +84,12 @@ async function detectReact(packageJson) {
|
|
84
84
|
}
|
85
85
|
log.errorLog("react");
|
86
86
|
}
|
87
|
-
async function detectTypescript(dirs) {
|
87
|
+
async function detectTypescript(packageJson, dirs) {
|
88
|
+
const typescriptVersion = getMinVersion(packageJson, "typescript", []);
|
89
|
+
if (!typescriptVersion) {
|
90
|
+
log.errorLog("typescript");
|
91
|
+
return;
|
92
|
+
}
|
88
93
|
let ts;
|
89
94
|
try {
|
90
95
|
ts = (await import("typescript")).default;
|
@@ -138,7 +143,7 @@ async function detectModules(packageJson, dirs) {
|
|
138
143
|
try {
|
139
144
|
const result = {};
|
140
145
|
log.log("Detecting modules");
|
141
|
-
result.ts = await detectTypescript(dirs);
|
146
|
+
result.ts = await detectTypescript(packageJson, dirs);
|
142
147
|
result.babel = await detectBabel(packageJson);
|
143
148
|
result.react = await detectReact(packageJson);
|
144
149
|
log.lineLog();
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"detectModules.js","sources":["../../../../src/detectModules.ts"],"sourcesContent":["import { type PackageJson } from \"./packageJson.js\";\nimport semver from \"semver\";\nimport { okLog, errorLog, log, lineLog, warnLog } from \"./log.js\";\nimport type { Dirs } from \"./resolveDirs.js\";\n\nexport type TS = {\n ts: typeof import(\"typescript\");\n parsedConfig: import(\"typescript\").ParsedCommandLine;\n host: import(\"typescript\").CompilerHost;\n};\nexport type DetectedModules = {\n ts?: TS;\n babel?: typeof import(\"@babel/core\");\n react?: \"legacy\" | \"modern\";\n};\n\ntype DepType =\n | \"dependencies\"\n | \"devDependencies\"\n | \"peerDependencies\"\n | \"optionalDependencies\";\nexport function getMinVersion(\n packageJson: PackageJson,\n depName: string,\n exclude: DepType[],\n): semver.SemVer | null {\n const allDepKeys = new Set<DepType>([\n \"dependencies\",\n \"devDependencies\",\n \"peerDependencies\",\n \"optionalDependencies\",\n ]);\n for (const e of exclude) {\n allDepKeys.delete(e);\n }\n\n let minVersion: semver.SemVer | null = null;\n for (const depKey of allDepKeys) {\n const depVersion = packageJson[depKey]?.[depName];\n if (depVersion) {\n const version = semver.minVersion(depVersion);\n if (!version) {\n warnLog(\"node-semver cannot parse version of\", depName, \"from\", depKey);\n warnLog(\"Version:\", depVersion);\n continue;\n }\n if (!minVersion) {\n minVersion = version;\n continue;\n }\n if (semver.lt(version, minVersion)) {\n minVersion = version;\n }\n }\n }\n\n return minVersion;\n}\n\nasync function detectBabel(\n packageJson: PackageJson,\n): Promise<typeof import(\"@babel/core\") | undefined> {\n if (\"@babel/core\" in (packageJson.optionalDependencies ?? {})) {\n errorLog(\"babel excluded because inside optionalDependencies\");\n return;\n }\n\n try {\n const babel = await import(\"@babel/core\");\n okLog(\"babel, version:\", babel.version);\n return babel;\n } catch {\n errorLog(\"babel\");\n }\n}\n\nasync function detectReact(\n packageJson: PackageJson,\n): Promise<\"legacy\" | \"modern\" | undefined> {\n const reactVersion = getMinVersion(packageJson, \"react\", [\"devDependencies\"]);\n if (reactVersion) {\n const isLegacy = semver.lt(reactVersion, \"17.0.0\");\n const transform = isLegacy ? \"legacy\" : \"modern\";\n okLog(\n `react, min version: ${reactVersion.version}. Transform: ${transform}`,\n );\n return transform;\n }\n errorLog(\"react\");\n}\n\nasync function detectTypescript(dirs: Dirs): Promise<TS | undefined> {\n let ts: typeof import(\"typescript\");\n try {\n // ts <=4.3 has no named exports. The all methods is located in the default export\n ts = (await import(\"typescript\")).default;\n } catch {\n errorLog(\"typescript\");\n return;\n }\n\n okLog(\"typescript, version:\", ts.version);\n\n const configFilePath = ts.findConfigFile(dirs.sourceDir, ts.sys.fileExists);\n if (!configFilePath) {\n throw new Error(\n \"Cannot find a tsconfig.json file. You should declare it. Please, read the https://github.com/XaveScor/smartbundle/issues/131 for more information\",\n );\n }\n const configFile = ts.readConfigFile(configFilePath, ts.sys.readFile);\n if (configFile.error) {\n const readableError = ts.flattenDiagnosticMessageText(\n configFile.error.messageText,\n \"\\n\",\n );\n throw new Error(`Cannot read tsconfig.json file, error: ${readableError}`);\n }\n const parsedConfig = ts.parseJsonConfigFileContent(\n configFile.config,\n ts.sys,\n dirs.sourceDir,\n {\n declaration: true,\n emitDeclarationOnly: true,\n strict: false,\n strictNullChecks: false,\n strictFunctionTypes: false,\n strictPropertyInitialization: false,\n skipLibCheck: true,\n skipDefaultLibCheck: true,\n outDir: \"\",\n // https://github.com/XaveScor/bobrik/issues/22#issuecomment-2308552352\n noEmit: false,\n },\n configFilePath,\n );\n\n if (!parsedConfig.options.verbatimModuleSyntax) {\n throw new Error(\n \"verbatimModuleSyntax should be enabled in tsconfig.json. Read https://github.com/XaveScor/smartbundle/issues/131 for more explanation.\\n\" +\n \"You also can upvote the issue if you need the support of verbatimModuleSyntax: false in your library\",\n );\n }\n\n const host = ts.createCompilerHost(parsedConfig.options);\n\n return { ts, parsedConfig, host };\n}\n\nexport async function detectModules(\n packageJson: PackageJson,\n dirs: Dirs,\n): Promise<\n | { error: false; modules: DetectedModules }\n | { error: true; errors: Array<string> }\n> {\n try {\n const result: DetectedModules = {};\n log(\"Detecting modules\");\n\n result.ts = await detectTypescript(dirs);\n result.babel = await detectBabel(packageJson);\n result.react = await detectReact(packageJson);\n\n lineLog();\n return { error: false, modules: result };\n } catch (e: any) {\n return { error: true, errors: [e.message] };\n }\n}\n"],"names":["warnLog","errorLog","okLog","log","lineLog"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBgB,SAAA,cACd,aACA,SACA,SACsB;;AAChB,QAAA,iCAAiB,IAAa;AAAA,IAClC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACD;AACD,aAAW,KAAK,SAAS;AACvB,eAAW,OAAO,CAAC;AAAA,EAAA;AAGrB,MAAI,aAAmC;AACvC,aAAW,UAAU,YAAY;AAC/B,UAAM,cAAa,iBAAY,MAAM,MAAlB,mBAAsB;AACzC,QAAI,YAAY;AACR,YAAA,UAAU,OAAO,WAAW,UAAU;AAC5C,UAAI,CAAC,SAAS;AACJA,YAAAA,QAAA,uCAAuC,SAAS,QAAQ,MAAM;AACtEA,YAAA,QAAQ,YAAY,UAAU;AAC9B;AAAA,MAAA;AAEF,UAAI,CAAC,YAAY;AACF,qBAAA;AACb;AAAA,MAAA;AAEF,UAAI,OAAO,GAAG,SAAS,UAAU,GAAG;AACrB,qBAAA;AAAA,MAAA;AAAA,IACf;AAAA,EACF;AAGK,SAAA;AACT;AAEA,eAAe,YACb,aACmD;AACnD,MAAI,kBAAkB,YAAY,wBAAwB,CAAK,IAAA;AAC7DC,QAAAA,SAAS,oDAAoD;AAC7D;AAAA,EAAA;AAGE,MAAA;AACI,UAAA,QAAQ,MAAM,OAAO,aAAa;AAClCC,cAAA,mBAAmB,MAAM,OAAO;AAC/B,WAAA;AAAA,EAAA,QACD;AACND,QAAAA,SAAS,OAAO;AAAA,EAAA;AAEpB;AAEA,eAAe,YACb,aAC0C;AAC1C,QAAM,eAAe,cAAc,aAAa,SAAS,CAAC,iBAAiB,CAAC;AAC5E,MAAI,cAAc;AAChB,UAAM,WAAW,OAAO,GAAG,cAAc,QAAQ;AAC3C,UAAA,YAAY,WAAW,WAAW;AACxCC,QAAA;AAAA,MACE,uBAAuB,aAAa,OAAO,gBAAgB,SAAS;AAAA,IACtE;AACO,WAAA;AAAA,EAAA;AAETD,MAAAA,SAAS,OAAO;AAClB;AAEA,eAAe,
|
1
|
+
{"version":3,"file":"detectModules.js","sources":["../../../../src/detectModules.ts"],"sourcesContent":["import { type PackageJson } from \"./packageJson.js\";\nimport semver from \"semver\";\nimport { okLog, errorLog, log, lineLog, warnLog } from \"./log.js\";\nimport type { Dirs } from \"./resolveDirs.js\";\n\nexport type TS = {\n ts: typeof import(\"typescript\");\n parsedConfig: import(\"typescript\").ParsedCommandLine;\n host: import(\"typescript\").CompilerHost;\n};\nexport type DetectedModules = {\n ts?: TS;\n babel?: typeof import(\"@babel/core\");\n react?: \"legacy\" | \"modern\";\n};\n\ntype DepType =\n | \"dependencies\"\n | \"devDependencies\"\n | \"peerDependencies\"\n | \"optionalDependencies\";\nexport function getMinVersion(\n packageJson: PackageJson,\n depName: string,\n exclude: DepType[],\n): semver.SemVer | null {\n const allDepKeys = new Set<DepType>([\n \"dependencies\",\n \"devDependencies\",\n \"peerDependencies\",\n \"optionalDependencies\",\n ]);\n for (const e of exclude) {\n allDepKeys.delete(e);\n }\n\n let minVersion: semver.SemVer | null = null;\n for (const depKey of allDepKeys) {\n const depVersion = packageJson[depKey]?.[depName];\n if (depVersion) {\n const version = semver.minVersion(depVersion);\n if (!version) {\n warnLog(\"node-semver cannot parse version of\", depName, \"from\", depKey);\n warnLog(\"Version:\", depVersion);\n continue;\n }\n if (!minVersion) {\n minVersion = version;\n continue;\n }\n if (semver.lt(version, minVersion)) {\n minVersion = version;\n }\n }\n }\n\n return minVersion;\n}\n\nasync function detectBabel(\n packageJson: PackageJson,\n): Promise<typeof import(\"@babel/core\") | undefined> {\n if (\"@babel/core\" in (packageJson.optionalDependencies ?? {})) {\n errorLog(\"babel excluded because inside optionalDependencies\");\n return;\n }\n\n try {\n const babel = await import(\"@babel/core\");\n okLog(\"babel, version:\", babel.version);\n return babel;\n } catch {\n errorLog(\"babel\");\n }\n}\n\nasync function detectReact(\n packageJson: PackageJson,\n): Promise<\"legacy\" | \"modern\" | undefined> {\n const reactVersion = getMinVersion(packageJson, \"react\", [\"devDependencies\"]);\n if (reactVersion) {\n const isLegacy = semver.lt(reactVersion, \"17.0.0\");\n const transform = isLegacy ? \"legacy\" : \"modern\";\n okLog(\n `react, min version: ${reactVersion.version}. Transform: ${transform}`,\n );\n return transform;\n }\n errorLog(\"react\");\n}\n\nasync function detectTypescript(\n packageJson: PackageJson,\n dirs: Dirs,\n): Promise<TS | undefined> {\n const typescriptVersion = getMinVersion(packageJson, \"typescript\", []);\n if (!typescriptVersion) {\n errorLog(\"typescript\");\n return;\n }\n\n let ts: typeof import(\"typescript\");\n try {\n // ts <=4.3 has no named exports. The all methods is located in the default export\n ts = (await import(\"typescript\")).default;\n } catch {\n errorLog(\"typescript\");\n return;\n }\n\n okLog(\"typescript, version:\", ts.version);\n\n const configFilePath = ts.findConfigFile(dirs.sourceDir, ts.sys.fileExists);\n if (!configFilePath) {\n throw new Error(\n \"Cannot find a tsconfig.json file. You should declare it. Please, read the https://github.com/XaveScor/smartbundle/issues/131 for more information\",\n );\n }\n const configFile = ts.readConfigFile(configFilePath, ts.sys.readFile);\n if (configFile.error) {\n const readableError = ts.flattenDiagnosticMessageText(\n configFile.error.messageText,\n \"\\n\",\n );\n throw new Error(`Cannot read tsconfig.json file, error: ${readableError}`);\n }\n const parsedConfig = ts.parseJsonConfigFileContent(\n configFile.config,\n ts.sys,\n dirs.sourceDir,\n {\n declaration: true,\n emitDeclarationOnly: true,\n strict: false,\n strictNullChecks: false,\n strictFunctionTypes: false,\n strictPropertyInitialization: false,\n skipLibCheck: true,\n skipDefaultLibCheck: true,\n outDir: \"\",\n // https://github.com/XaveScor/bobrik/issues/22#issuecomment-2308552352\n noEmit: false,\n },\n configFilePath,\n );\n\n if (!parsedConfig.options.verbatimModuleSyntax) {\n throw new Error(\n \"verbatimModuleSyntax should be enabled in tsconfig.json. Read https://github.com/XaveScor/smartbundle/issues/131 for more explanation.\\n\" +\n \"You also can upvote the issue if you need the support of verbatimModuleSyntax: false in your library\",\n );\n }\n\n const host = ts.createCompilerHost(parsedConfig.options);\n\n return { ts, parsedConfig, host };\n}\n\nexport async function detectModules(\n packageJson: PackageJson,\n dirs: Dirs,\n): Promise<\n | { error: false; modules: DetectedModules }\n | { error: true; errors: Array<string> }\n> {\n try {\n const result: DetectedModules = {};\n log(\"Detecting modules\");\n\n result.ts = await detectTypescript(packageJson, dirs);\n result.babel = await detectBabel(packageJson);\n result.react = await detectReact(packageJson);\n\n lineLog();\n return { error: false, modules: result };\n } catch (e: any) {\n return { error: true, errors: [e.message] };\n }\n}\n"],"names":["warnLog","errorLog","okLog","log","lineLog"],"mappings":"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"}
|
@@ -20,6 +20,11 @@ async function buildTypesTask({
|
|
20
20
|
const reversedEntrypoints = utils.reverseMap(entrypoints);
|
21
21
|
const entrypointToEsDtsMap = /* @__PURE__ */ new Map();
|
22
22
|
const entrypointToCjsDtsMap = /* @__PURE__ */ new Map();
|
23
|
+
if (tsEntrypoints.length > 0 && modules.ts == null) {
|
24
|
+
throw new Error(
|
25
|
+
'smartbundle found the .ts entrypoint but required "typescript" to build .d.ts files. Please install the "typescript" dependency.'
|
26
|
+
);
|
27
|
+
}
|
23
28
|
if (tsEntrypoints.length === 0 || modules.ts == null) {
|
24
29
|
return { entrypointToEsDtsMap, entrypointToCjsDtsMap };
|
25
30
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"buildTypesTask.js","sources":["../../../../../../src/tasks/buildTypesTask/buildTypesTask.ts"],"sourcesContent":["import { callTypescript } from \"./callTypescript.js\";\nimport { reverseMap } from \"../utils.js\";\nimport { okLog } from \"../../log.js\";\nimport type { DetectedModules } from \"../../detectModules.js\";\nimport { type PackageJson } from \"../../packageJson.js\";\nimport { type Dirs } from \"../../resolveDirs.js\";\n\ntype BuildTypesTaskOption = {\n entrypoints: Map<string, string>;\n dirs: Dirs;\n modules: DetectedModules;\n packageJson: PackageJson;\n};\n\nexport async function buildTypesTask({\n entrypoints,\n dirs,\n packageJson,\n modules,\n}: BuildTypesTaskOption) {\n const { outDir } = dirs;\n const tsEntrypoints = [...entrypoints.values()].filter((entry) =>\n entry.endsWith(\".ts\"),\n );\n const reversedEntrypoints = reverseMap(entrypoints);\n\n const entrypointToEsDtsMap = new Map<string, string>();\n const entrypointToCjsDtsMap = new Map<string, string>();\n if (tsEntrypoints.length === 0 || modules.ts == null) {\n return { entrypointToEsDtsMap, entrypointToCjsDtsMap };\n }\n\n const dtsMap = await callTypescript({\n ts: modules.ts,\n dirs,\n packageJson,\n tsEntrypoints,\n outDir,\n });\n\n for (const [source, dts] of dtsMap.sourceToEsmDtsMap) {\n const entrypoints = reversedEntrypoints.get(source);\n if (entrypoints) {\n for (const entrypoint of entrypoints) {\n entrypointToEsDtsMap.set(entrypoint, dts);\n }\n }\n }\n\n for (const [source, dts] of dtsMap.sourceToCjsDtsMap) {\n const entrypoints = reversedEntrypoints.get(source);\n if (entrypoints) {\n for (const entrypoint of entrypoints) {\n entrypointToCjsDtsMap.set(entrypoint, dts);\n }\n }\n }\n\n okLog(\".d.ts\");\n\n return { entrypointToEsDtsMap, entrypointToCjsDtsMap };\n}\n"],"names":["reverseMap","callTypescript","entrypoints","okLog"],"mappings":";;;;;;;;;AAcA,eAAsB,eAAe;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAyB;AACjB,QAAA,EAAE,WAAW;AACnB,QAAM,gBAAgB,CAAC,GAAG,YAAY,OAAA,CAAQ,EAAE;AAAA,IAAO,CAAC,UACtD,MAAM,SAAS,KAAK;AAAA,EACtB;AACM,QAAA,sBAAsBA,iBAAW,WAAW;AAE5C,QAAA,2CAA2B,IAAoB;AAC/C,QAAA,4CAA4B,IAAoB;AACtD,MAAI,cAAc,WAAW,KAAK,QAAQ,MAAM,MAAM;AAC7C,WAAA,EAAE,sBAAsB,sBAAsB;AAAA,EAAA;AAGjD,QAAA,SAAS,MAAMC,8BAAe;AAAA,IAClC,IAAI,QAAQ;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACD;AAED,aAAW,CAAC,QAAQ,GAAG,KAAK,OAAO,mBAAmB;AAC9CC,UAAAA,eAAc,oBAAoB,IAAI,MAAM;AAClD,QAAIA,cAAa;AACf,iBAAW,cAAcA,cAAa;AACf,6BAAA,IAAI,YAAY,GAAG;AAAA,MAAA;AAAA,IAC1C;AAAA,EACF;AAGF,aAAW,CAAC,QAAQ,GAAG,KAAK,OAAO,mBAAmB;AAC9CA,UAAAA,eAAc,oBAAoB,IAAI,MAAM;AAClD,QAAIA,cAAa;AACf,iBAAW,cAAcA,cAAa;AACd,8BAAA,IAAI,YAAY,GAAG;AAAA,MAAA;AAAA,IAC3C;AAAA,EACF;AAGFC,MAAAA,MAAM,OAAO;AAEN,SAAA,EAAE,sBAAsB,sBAAsB;AACvD;;"}
|
1
|
+
{"version":3,"file":"buildTypesTask.js","sources":["../../../../../../src/tasks/buildTypesTask/buildTypesTask.ts"],"sourcesContent":["import { callTypescript } from \"./callTypescript.js\";\nimport { reverseMap } from \"../utils.js\";\nimport { okLog } from \"../../log.js\";\nimport type { DetectedModules } from \"../../detectModules.js\";\nimport { type PackageJson } from \"../../packageJson.js\";\nimport { type Dirs } from \"../../resolveDirs.js\";\n\ntype BuildTypesTaskOption = {\n entrypoints: Map<string, string>;\n dirs: Dirs;\n modules: DetectedModules;\n packageJson: PackageJson;\n};\n\nexport async function buildTypesTask({\n entrypoints,\n dirs,\n packageJson,\n modules,\n}: BuildTypesTaskOption) {\n const { outDir } = dirs;\n const tsEntrypoints = [...entrypoints.values()].filter((entry) =>\n entry.endsWith(\".ts\"),\n );\n const reversedEntrypoints = reverseMap(entrypoints);\n\n const entrypointToEsDtsMap = new Map<string, string>();\n const entrypointToCjsDtsMap = new Map<string, string>();\n if (tsEntrypoints.length > 0 && modules.ts == null) {\n throw new Error(\n 'smartbundle found the .ts entrypoint but required \"typescript\" to build .d.ts files. Please install the \"typescript\" dependency.',\n );\n }\n if (tsEntrypoints.length === 0 || modules.ts == null) {\n return { entrypointToEsDtsMap, entrypointToCjsDtsMap };\n }\n\n const dtsMap = await callTypescript({\n ts: modules.ts,\n dirs,\n packageJson,\n tsEntrypoints,\n outDir,\n });\n\n for (const [source, dts] of dtsMap.sourceToEsmDtsMap) {\n const entrypoints = reversedEntrypoints.get(source);\n if (entrypoints) {\n for (const entrypoint of entrypoints) {\n entrypointToEsDtsMap.set(entrypoint, dts);\n }\n }\n }\n\n for (const [source, dts] of dtsMap.sourceToCjsDtsMap) {\n const entrypoints = reversedEntrypoints.get(source);\n if (entrypoints) {\n for (const entrypoint of entrypoints) {\n entrypointToCjsDtsMap.set(entrypoint, dts);\n }\n }\n }\n\n okLog(\".d.ts\");\n\n return { entrypointToEsDtsMap, entrypointToCjsDtsMap };\n}\n"],"names":["reverseMap","callTypescript","entrypoints","okLog"],"mappings":";;;;;;;;;AAcA,eAAsB,eAAe;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAyB;AACjB,QAAA,EAAE,WAAW;AACnB,QAAM,gBAAgB,CAAC,GAAG,YAAY,OAAA,CAAQ,EAAE;AAAA,IAAO,CAAC,UACtD,MAAM,SAAS,KAAK;AAAA,EACtB;AACM,QAAA,sBAAsBA,iBAAW,WAAW;AAE5C,QAAA,2CAA2B,IAAoB;AAC/C,QAAA,4CAA4B,IAAoB;AACtD,MAAI,cAAc,SAAS,KAAK,QAAQ,MAAM,MAAM;AAClD,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EAAA;AAEF,MAAI,cAAc,WAAW,KAAK,QAAQ,MAAM,MAAM;AAC7C,WAAA,EAAE,sBAAsB,sBAAsB;AAAA,EAAA;AAGjD,QAAA,SAAS,MAAMC,8BAAe;AAAA,IAClC,IAAI,QAAQ;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACD;AAED,aAAW,CAAC,QAAQ,GAAG,KAAK,OAAO,mBAAmB;AAC9CC,UAAAA,eAAc,oBAAoB,IAAI,MAAM;AAClD,QAAIA,cAAa;AACf,iBAAW,cAAcA,cAAa;AACf,6BAAA,IAAI,YAAY,GAAG;AAAA,MAAA;AAAA,IAC1C;AAAA,EACF;AAGF,aAAW,CAAC,QAAQ,GAAG,KAAK,OAAO,mBAAmB;AAC9CA,UAAAA,eAAc,oBAAoB,IAAI,MAAM;AAClD,QAAIA,cAAa;AACf,iBAAW,cAAcA,cAAa;AACd,8BAAA,IAAI,YAAY,GAAG;AAAA,MAAA;AAAA,IAC3C;AAAA,EACF;AAGFC,MAAAA,MAAM,OAAO;AAEN,SAAA,EAAE,sBAAsB,sBAAsB;AACvD;;"}
|
@@ -60,7 +60,12 @@ async function detectReact(packageJson) {
|
|
60
60
|
}
|
61
61
|
errorLog("react");
|
62
62
|
}
|
63
|
-
async function detectTypescript(dirs) {
|
63
|
+
async function detectTypescript(packageJson, dirs) {
|
64
|
+
const typescriptVersion = getMinVersion(packageJson, "typescript", []);
|
65
|
+
if (!typescriptVersion) {
|
66
|
+
errorLog("typescript");
|
67
|
+
return;
|
68
|
+
}
|
64
69
|
let ts;
|
65
70
|
try {
|
66
71
|
ts = (await import("typescript")).default;
|
@@ -114,7 +119,7 @@ async function detectModules(packageJson, dirs) {
|
|
114
119
|
try {
|
115
120
|
const result = {};
|
116
121
|
log("Detecting modules");
|
117
|
-
result.ts = await detectTypescript(dirs);
|
122
|
+
result.ts = await detectTypescript(packageJson, dirs);
|
118
123
|
result.babel = await detectBabel(packageJson);
|
119
124
|
result.react = await detectReact(packageJson);
|
120
125
|
lineLog();
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"detectModules.mjs","sources":["../../../../src/detectModules.ts"],"sourcesContent":["import { type PackageJson } from \"./packageJson.js\";\nimport semver from \"semver\";\nimport { okLog, errorLog, log, lineLog, warnLog } from \"./log.js\";\nimport type { Dirs } from \"./resolveDirs.js\";\n\nexport type TS = {\n ts: typeof import(\"typescript\");\n parsedConfig: import(\"typescript\").ParsedCommandLine;\n host: import(\"typescript\").CompilerHost;\n};\nexport type DetectedModules = {\n ts?: TS;\n babel?: typeof import(\"@babel/core\");\n react?: \"legacy\" | \"modern\";\n};\n\ntype DepType =\n | \"dependencies\"\n | \"devDependencies\"\n | \"peerDependencies\"\n | \"optionalDependencies\";\nexport function getMinVersion(\n packageJson: PackageJson,\n depName: string,\n exclude: DepType[],\n): semver.SemVer | null {\n const allDepKeys = new Set<DepType>([\n \"dependencies\",\n \"devDependencies\",\n \"peerDependencies\",\n \"optionalDependencies\",\n ]);\n for (const e of exclude) {\n allDepKeys.delete(e);\n }\n\n let minVersion: semver.SemVer | null = null;\n for (const depKey of allDepKeys) {\n const depVersion = packageJson[depKey]?.[depName];\n if (depVersion) {\n const version = semver.minVersion(depVersion);\n if (!version) {\n warnLog(\"node-semver cannot parse version of\", depName, \"from\", depKey);\n warnLog(\"Version:\", depVersion);\n continue;\n }\n if (!minVersion) {\n minVersion = version;\n continue;\n }\n if (semver.lt(version, minVersion)) {\n minVersion = version;\n }\n }\n }\n\n return minVersion;\n}\n\nasync function detectBabel(\n packageJson: PackageJson,\n): Promise<typeof import(\"@babel/core\") | undefined> {\n if (\"@babel/core\" in (packageJson.optionalDependencies ?? {})) {\n errorLog(\"babel excluded because inside optionalDependencies\");\n return;\n }\n\n try {\n const babel = await import(\"@babel/core\");\n okLog(\"babel, version:\", babel.version);\n return babel;\n } catch {\n errorLog(\"babel\");\n }\n}\n\nasync function detectReact(\n packageJson: PackageJson,\n): Promise<\"legacy\" | \"modern\" | undefined> {\n const reactVersion = getMinVersion(packageJson, \"react\", [\"devDependencies\"]);\n if (reactVersion) {\n const isLegacy = semver.lt(reactVersion, \"17.0.0\");\n const transform = isLegacy ? \"legacy\" : \"modern\";\n okLog(\n `react, min version: ${reactVersion.version}. Transform: ${transform}`,\n );\n return transform;\n }\n errorLog(\"react\");\n}\n\nasync function detectTypescript(dirs: Dirs): Promise<TS | undefined> {\n let ts: typeof import(\"typescript\");\n try {\n // ts <=4.3 has no named exports. The all methods is located in the default export\n ts = (await import(\"typescript\")).default;\n } catch {\n errorLog(\"typescript\");\n return;\n }\n\n okLog(\"typescript, version:\", ts.version);\n\n const configFilePath = ts.findConfigFile(dirs.sourceDir, ts.sys.fileExists);\n if (!configFilePath) {\n throw new Error(\n \"Cannot find a tsconfig.json file. You should declare it. Please, read the https://github.com/XaveScor/smartbundle/issues/131 for more information\",\n );\n }\n const configFile = ts.readConfigFile(configFilePath, ts.sys.readFile);\n if (configFile.error) {\n const readableError = ts.flattenDiagnosticMessageText(\n configFile.error.messageText,\n \"\\n\",\n );\n throw new Error(`Cannot read tsconfig.json file, error: ${readableError}`);\n }\n const parsedConfig = ts.parseJsonConfigFileContent(\n configFile.config,\n ts.sys,\n dirs.sourceDir,\n {\n declaration: true,\n emitDeclarationOnly: true,\n strict: false,\n strictNullChecks: false,\n strictFunctionTypes: false,\n strictPropertyInitialization: false,\n skipLibCheck: true,\n skipDefaultLibCheck: true,\n outDir: \"\",\n // https://github.com/XaveScor/bobrik/issues/22#issuecomment-2308552352\n noEmit: false,\n },\n configFilePath,\n );\n\n if (!parsedConfig.options.verbatimModuleSyntax) {\n throw new Error(\n \"verbatimModuleSyntax should be enabled in tsconfig.json. Read https://github.com/XaveScor/smartbundle/issues/131 for more explanation.\\n\" +\n \"You also can upvote the issue if you need the support of verbatimModuleSyntax: false in your library\",\n );\n }\n\n const host = ts.createCompilerHost(parsedConfig.options);\n\n return { ts, parsedConfig, host };\n}\n\nexport async function detectModules(\n packageJson: PackageJson,\n dirs: Dirs,\n): Promise<\n | { error: false; modules: DetectedModules }\n | { error: true; errors: Array<string> }\n> {\n try {\n const result: DetectedModules = {};\n log(\"Detecting modules\");\n\n result.ts = await detectTypescript(dirs);\n result.babel = await detectBabel(packageJson);\n result.react = await detectReact(packageJson);\n\n lineLog();\n return { error: false, modules: result };\n } catch (e: any) {\n return { error: true, errors: [e.message] };\n }\n}\n"],"names":[],"mappings":";;;;;AAqBgB,SAAA,cACd,aACA,SACA,SACsB;;AAChB,QAAA,iCAAiB,IAAa;AAAA,IAClC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACD;AACD,aAAW,KAAK,SAAS;AACvB,eAAW,OAAO,CAAC;AAAA,EAAA;AAGrB,MAAI,aAAmC;AACvC,aAAW,UAAU,YAAY;AAC/B,UAAM,cAAa,iBAAY,MAAM,MAAlB,mBAAsB;AACzC,QAAI,YAAY;AACR,YAAA,UAAU,OAAO,WAAW,UAAU;AAC5C,UAAI,CAAC,SAAS;AACJ,gBAAA,uCAAuC,SAAS,QAAQ,MAAM;AACtE,gBAAQ,YAAY,UAAU;AAC9B;AAAA,MAAA;AAEF,UAAI,CAAC,YAAY;AACF,qBAAA;AACb;AAAA,MAAA;AAEF,UAAI,OAAO,GAAG,SAAS,UAAU,GAAG;AACrB,qBAAA;AAAA,MAAA;AAAA,IACf;AAAA,EACF;AAGK,SAAA;AACT;AAEA,eAAe,YACb,aACmD;AACnD,MAAI,kBAAkB,YAAY,wBAAwB,CAAK,IAAA;AAC7D,aAAS,oDAAoD;AAC7D;AAAA,EAAA;AAGE,MAAA;AACI,UAAA,QAAQ,MAAM,OAAO,aAAa;AAClC,UAAA,mBAAmB,MAAM,OAAO;AAC/B,WAAA;AAAA,EAAA,QACD;AACN,aAAS,OAAO;AAAA,EAAA;AAEpB;AAEA,eAAe,YACb,aAC0C;AAC1C,QAAM,eAAe,cAAc,aAAa,SAAS,CAAC,iBAAiB,CAAC;AAC5E,MAAI,cAAc;AAChB,UAAM,WAAW,OAAO,GAAG,cAAc,QAAQ;AAC3C,UAAA,YAAY,WAAW,WAAW;AACxC;AAAA,MACE,uBAAuB,aAAa,OAAO,gBAAgB,SAAS;AAAA,IACtE;AACO,WAAA;AAAA,EAAA;AAET,WAAS,OAAO;AAClB;AAEA,eAAe,
|
1
|
+
{"version":3,"file":"detectModules.mjs","sources":["../../../../src/detectModules.ts"],"sourcesContent":["import { type PackageJson } from \"./packageJson.js\";\nimport semver from \"semver\";\nimport { okLog, errorLog, log, lineLog, warnLog } from \"./log.js\";\nimport type { Dirs } from \"./resolveDirs.js\";\n\nexport type TS = {\n ts: typeof import(\"typescript\");\n parsedConfig: import(\"typescript\").ParsedCommandLine;\n host: import(\"typescript\").CompilerHost;\n};\nexport type DetectedModules = {\n ts?: TS;\n babel?: typeof import(\"@babel/core\");\n react?: \"legacy\" | \"modern\";\n};\n\ntype DepType =\n | \"dependencies\"\n | \"devDependencies\"\n | \"peerDependencies\"\n | \"optionalDependencies\";\nexport function getMinVersion(\n packageJson: PackageJson,\n depName: string,\n exclude: DepType[],\n): semver.SemVer | null {\n const allDepKeys = new Set<DepType>([\n \"dependencies\",\n \"devDependencies\",\n \"peerDependencies\",\n \"optionalDependencies\",\n ]);\n for (const e of exclude) {\n allDepKeys.delete(e);\n }\n\n let minVersion: semver.SemVer | null = null;\n for (const depKey of allDepKeys) {\n const depVersion = packageJson[depKey]?.[depName];\n if (depVersion) {\n const version = semver.minVersion(depVersion);\n if (!version) {\n warnLog(\"node-semver cannot parse version of\", depName, \"from\", depKey);\n warnLog(\"Version:\", depVersion);\n continue;\n }\n if (!minVersion) {\n minVersion = version;\n continue;\n }\n if (semver.lt(version, minVersion)) {\n minVersion = version;\n }\n }\n }\n\n return minVersion;\n}\n\nasync function detectBabel(\n packageJson: PackageJson,\n): Promise<typeof import(\"@babel/core\") | undefined> {\n if (\"@babel/core\" in (packageJson.optionalDependencies ?? {})) {\n errorLog(\"babel excluded because inside optionalDependencies\");\n return;\n }\n\n try {\n const babel = await import(\"@babel/core\");\n okLog(\"babel, version:\", babel.version);\n return babel;\n } catch {\n errorLog(\"babel\");\n }\n}\n\nasync function detectReact(\n packageJson: PackageJson,\n): Promise<\"legacy\" | \"modern\" | undefined> {\n const reactVersion = getMinVersion(packageJson, \"react\", [\"devDependencies\"]);\n if (reactVersion) {\n const isLegacy = semver.lt(reactVersion, \"17.0.0\");\n const transform = isLegacy ? \"legacy\" : \"modern\";\n okLog(\n `react, min version: ${reactVersion.version}. Transform: ${transform}`,\n );\n return transform;\n }\n errorLog(\"react\");\n}\n\nasync function detectTypescript(\n packageJson: PackageJson,\n dirs: Dirs,\n): Promise<TS | undefined> {\n const typescriptVersion = getMinVersion(packageJson, \"typescript\", []);\n if (!typescriptVersion) {\n errorLog(\"typescript\");\n return;\n }\n\n let ts: typeof import(\"typescript\");\n try {\n // ts <=4.3 has no named exports. The all methods is located in the default export\n ts = (await import(\"typescript\")).default;\n } catch {\n errorLog(\"typescript\");\n return;\n }\n\n okLog(\"typescript, version:\", ts.version);\n\n const configFilePath = ts.findConfigFile(dirs.sourceDir, ts.sys.fileExists);\n if (!configFilePath) {\n throw new Error(\n \"Cannot find a tsconfig.json file. You should declare it. Please, read the https://github.com/XaveScor/smartbundle/issues/131 for more information\",\n );\n }\n const configFile = ts.readConfigFile(configFilePath, ts.sys.readFile);\n if (configFile.error) {\n const readableError = ts.flattenDiagnosticMessageText(\n configFile.error.messageText,\n \"\\n\",\n );\n throw new Error(`Cannot read tsconfig.json file, error: ${readableError}`);\n }\n const parsedConfig = ts.parseJsonConfigFileContent(\n configFile.config,\n ts.sys,\n dirs.sourceDir,\n {\n declaration: true,\n emitDeclarationOnly: true,\n strict: false,\n strictNullChecks: false,\n strictFunctionTypes: false,\n strictPropertyInitialization: false,\n skipLibCheck: true,\n skipDefaultLibCheck: true,\n outDir: \"\",\n // https://github.com/XaveScor/bobrik/issues/22#issuecomment-2308552352\n noEmit: false,\n },\n configFilePath,\n );\n\n if (!parsedConfig.options.verbatimModuleSyntax) {\n throw new Error(\n \"verbatimModuleSyntax should be enabled in tsconfig.json. Read https://github.com/XaveScor/smartbundle/issues/131 for more explanation.\\n\" +\n \"You also can upvote the issue if you need the support of verbatimModuleSyntax: false in your library\",\n );\n }\n\n const host = ts.createCompilerHost(parsedConfig.options);\n\n return { ts, parsedConfig, host };\n}\n\nexport async function detectModules(\n packageJson: PackageJson,\n dirs: Dirs,\n): Promise<\n | { error: false; modules: DetectedModules }\n | { error: true; errors: Array<string> }\n> {\n try {\n const result: DetectedModules = {};\n log(\"Detecting modules\");\n\n result.ts = await detectTypescript(packageJson, dirs);\n result.babel = await detectBabel(packageJson);\n result.react = await detectReact(packageJson);\n\n lineLog();\n return { error: false, modules: result };\n } catch (e: any) {\n return { error: true, errors: [e.message] };\n }\n}\n"],"names":[],"mappings":"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"}
|
@@ -18,6 +18,11 @@ async function buildTypesTask({
|
|
18
18
|
const reversedEntrypoints = reverseMap(entrypoints);
|
19
19
|
const entrypointToEsDtsMap = /* @__PURE__ */ new Map();
|
20
20
|
const entrypointToCjsDtsMap = /* @__PURE__ */ new Map();
|
21
|
+
if (tsEntrypoints.length > 0 && modules.ts == null) {
|
22
|
+
throw new Error(
|
23
|
+
'smartbundle found the .ts entrypoint but required "typescript" to build .d.ts files. Please install the "typescript" dependency.'
|
24
|
+
);
|
25
|
+
}
|
21
26
|
if (tsEntrypoints.length === 0 || modules.ts == null) {
|
22
27
|
return { entrypointToEsDtsMap, entrypointToCjsDtsMap };
|
23
28
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"buildTypesTask.mjs","sources":["../../../../../../src/tasks/buildTypesTask/buildTypesTask.ts"],"sourcesContent":["import { callTypescript } from \"./callTypescript.js\";\nimport { reverseMap } from \"../utils.js\";\nimport { okLog } from \"../../log.js\";\nimport type { DetectedModules } from \"../../detectModules.js\";\nimport { type PackageJson } from \"../../packageJson.js\";\nimport { type Dirs } from \"../../resolveDirs.js\";\n\ntype BuildTypesTaskOption = {\n entrypoints: Map<string, string>;\n dirs: Dirs;\n modules: DetectedModules;\n packageJson: PackageJson;\n};\n\nexport async function buildTypesTask({\n entrypoints,\n dirs,\n packageJson,\n modules,\n}: BuildTypesTaskOption) {\n const { outDir } = dirs;\n const tsEntrypoints = [...entrypoints.values()].filter((entry) =>\n entry.endsWith(\".ts\"),\n );\n const reversedEntrypoints = reverseMap(entrypoints);\n\n const entrypointToEsDtsMap = new Map<string, string>();\n const entrypointToCjsDtsMap = new Map<string, string>();\n if (tsEntrypoints.length === 0 || modules.ts == null) {\n return { entrypointToEsDtsMap, entrypointToCjsDtsMap };\n }\n\n const dtsMap = await callTypescript({\n ts: modules.ts,\n dirs,\n packageJson,\n tsEntrypoints,\n outDir,\n });\n\n for (const [source, dts] of dtsMap.sourceToEsmDtsMap) {\n const entrypoints = reversedEntrypoints.get(source);\n if (entrypoints) {\n for (const entrypoint of entrypoints) {\n entrypointToEsDtsMap.set(entrypoint, dts);\n }\n }\n }\n\n for (const [source, dts] of dtsMap.sourceToCjsDtsMap) {\n const entrypoints = reversedEntrypoints.get(source);\n if (entrypoints) {\n for (const entrypoint of entrypoints) {\n entrypointToCjsDtsMap.set(entrypoint, dts);\n }\n }\n }\n\n okLog(\".d.ts\");\n\n return { entrypointToEsDtsMap, entrypointToCjsDtsMap };\n}\n"],"names":["entrypoints"],"mappings":";;;;;;;AAcA,eAAsB,eAAe;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAyB;AACjB,QAAA,EAAE,WAAW;AACnB,QAAM,gBAAgB,CAAC,GAAG,YAAY,OAAA,CAAQ,EAAE;AAAA,IAAO,CAAC,UACtD,MAAM,SAAS,KAAK;AAAA,EACtB;AACM,QAAA,sBAAsB,WAAW,WAAW;AAE5C,QAAA,2CAA2B,IAAoB;AAC/C,QAAA,4CAA4B,IAAoB;AACtD,MAAI,cAAc,WAAW,KAAK,QAAQ,MAAM,MAAM;AAC7C,WAAA,EAAE,sBAAsB,sBAAsB;AAAA,EAAA;AAGjD,QAAA,SAAS,MAAM,eAAe;AAAA,IAClC,IAAI,QAAQ;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACD;AAED,aAAW,CAAC,QAAQ,GAAG,KAAK,OAAO,mBAAmB;AAC9CA,UAAAA,eAAc,oBAAoB,IAAI,MAAM;AAClD,QAAIA,cAAa;AACf,iBAAW,cAAcA,cAAa;AACf,6BAAA,IAAI,YAAY,GAAG;AAAA,MAAA;AAAA,IAC1C;AAAA,EACF;AAGF,aAAW,CAAC,QAAQ,GAAG,KAAK,OAAO,mBAAmB;AAC9CA,UAAAA,eAAc,oBAAoB,IAAI,MAAM;AAClD,QAAIA,cAAa;AACf,iBAAW,cAAcA,cAAa;AACd,8BAAA,IAAI,YAAY,GAAG;AAAA,MAAA;AAAA,IAC3C;AAAA,EACF;AAGF,QAAM,OAAO;AAEN,SAAA,EAAE,sBAAsB,sBAAsB;AACvD;"}
|
1
|
+
{"version":3,"file":"buildTypesTask.mjs","sources":["../../../../../../src/tasks/buildTypesTask/buildTypesTask.ts"],"sourcesContent":["import { callTypescript } from \"./callTypescript.js\";\nimport { reverseMap } from \"../utils.js\";\nimport { okLog } from \"../../log.js\";\nimport type { DetectedModules } from \"../../detectModules.js\";\nimport { type PackageJson } from \"../../packageJson.js\";\nimport { type Dirs } from \"../../resolveDirs.js\";\n\ntype BuildTypesTaskOption = {\n entrypoints: Map<string, string>;\n dirs: Dirs;\n modules: DetectedModules;\n packageJson: PackageJson;\n};\n\nexport async function buildTypesTask({\n entrypoints,\n dirs,\n packageJson,\n modules,\n}: BuildTypesTaskOption) {\n const { outDir } = dirs;\n const tsEntrypoints = [...entrypoints.values()].filter((entry) =>\n entry.endsWith(\".ts\"),\n );\n const reversedEntrypoints = reverseMap(entrypoints);\n\n const entrypointToEsDtsMap = new Map<string, string>();\n const entrypointToCjsDtsMap = new Map<string, string>();\n if (tsEntrypoints.length > 0 && modules.ts == null) {\n throw new Error(\n 'smartbundle found the .ts entrypoint but required \"typescript\" to build .d.ts files. Please install the \"typescript\" dependency.',\n );\n }\n if (tsEntrypoints.length === 0 || modules.ts == null) {\n return { entrypointToEsDtsMap, entrypointToCjsDtsMap };\n }\n\n const dtsMap = await callTypescript({\n ts: modules.ts,\n dirs,\n packageJson,\n tsEntrypoints,\n outDir,\n });\n\n for (const [source, dts] of dtsMap.sourceToEsmDtsMap) {\n const entrypoints = reversedEntrypoints.get(source);\n if (entrypoints) {\n for (const entrypoint of entrypoints) {\n entrypointToEsDtsMap.set(entrypoint, dts);\n }\n }\n }\n\n for (const [source, dts] of dtsMap.sourceToCjsDtsMap) {\n const entrypoints = reversedEntrypoints.get(source);\n if (entrypoints) {\n for (const entrypoint of entrypoints) {\n entrypointToCjsDtsMap.set(entrypoint, dts);\n }\n }\n }\n\n okLog(\".d.ts\");\n\n return { entrypointToEsDtsMap, entrypointToCjsDtsMap };\n}\n"],"names":["entrypoints"],"mappings":";;;;;;;AAcA,eAAsB,eAAe;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAyB;AACjB,QAAA,EAAE,WAAW;AACnB,QAAM,gBAAgB,CAAC,GAAG,YAAY,OAAA,CAAQ,EAAE;AAAA,IAAO,CAAC,UACtD,MAAM,SAAS,KAAK;AAAA,EACtB;AACM,QAAA,sBAAsB,WAAW,WAAW;AAE5C,QAAA,2CAA2B,IAAoB;AAC/C,QAAA,4CAA4B,IAAoB;AACtD,MAAI,cAAc,SAAS,KAAK,QAAQ,MAAM,MAAM;AAClD,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EAAA;AAEF,MAAI,cAAc,WAAW,KAAK,QAAQ,MAAM,MAAM;AAC7C,WAAA,EAAE,sBAAsB,sBAAsB;AAAA,EAAA;AAGjD,QAAA,SAAS,MAAM,eAAe;AAAA,IAClC,IAAI,QAAQ;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACD;AAED,aAAW,CAAC,QAAQ,GAAG,KAAK,OAAO,mBAAmB;AAC9CA,UAAAA,eAAc,oBAAoB,IAAI,MAAM;AAClD,QAAIA,cAAa;AACf,iBAAW,cAAcA,cAAa;AACf,6BAAA,IAAI,YAAY,GAAG;AAAA,MAAA;AAAA,IAC1C;AAAA,EACF;AAGF,aAAW,CAAC,QAAQ,GAAG,KAAK,OAAO,mBAAmB;AAC9CA,UAAAA,eAAc,oBAAoB,IAAI,MAAM;AAClD,QAAIA,cAAa;AACf,iBAAW,cAAcA,cAAa;AACd,8BAAA,IAAI,YAAY,GAAG;AAAA,MAAA;AAAA,IAC3C;AAAA,EACF;AAGF,QAAM,OAAO;AAEN,SAAA,EAAE,sBAAsB,sBAAsB;AACvD;"}
|