smartbundle 0.13.0 → 0.13.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,7 +15,7 @@ async function buildTypesTask({
15
15
  }) {
16
16
  const { outDir } = dirs;
17
17
  const tsEntrypoints = [...entrypoints.values()].filter(
18
- (entry) => entry.endsWith(".ts")
18
+ (entry) => entry.endsWith(".ts") || entry.endsWith(".tsx")
19
19
  );
20
20
  const reversedEntrypoints = utils.reverseMap(entrypoints);
21
21
  const entrypointToEsDtsMap = /* @__PURE__ */ new Map();
@@ -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 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;;"}
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\") || entry.endsWith(\".tsx\"),\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,KAAK,MAAM,SAAS,MAAM;AAAA,EAChD;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;;"}
@@ -50,17 +50,20 @@ async function callTypescript({
50
50
  );
51
51
  program.emit(void 0, (fileName, data) => {
52
52
  const relativePath = path__namespace.relative(sourceDir, fileName);
53
- const sourceFileName = fileName.replace(/\.d\.ts$/, ".ts");
53
+ const sourceFileNameTS = fileName.replace(/\.d\.ts$/, ".ts");
54
+ const sourceFileNameTSX = fileName.replace(/\.d\.ts$/, ".tsx");
54
55
  const finalEsmPath = path__namespace.join(esmOutDir, relativePath);
55
56
  const esmFinalPath = finalEsmPath.replace(/\.d\.ts$/, ".d.mts");
56
- sourceToEsmDtsMap.set(sourceFileName, esmFinalPath);
57
+ sourceToEsmDtsMap.set(sourceFileNameTS, esmFinalPath);
58
+ sourceToEsmDtsMap.set(sourceFileNameTSX, esmFinalPath);
57
59
  fs__namespace.mkdirSync(path__namespace.dirname(esmFinalPath), { recursive: true });
58
60
  fs__namespace.writeFileSync(esmFinalPath, data);
59
61
  const finalCjsPath = path__namespace.join(cjsOutDir, relativePath);
60
62
  fs__namespace.mkdirSync(path__namespace.dirname(finalCjsPath), { recursive: true });
61
63
  const cjsFinalPath = finalCjsPath;
62
64
  fs__namespace.writeFileSync(cjsFinalPath, data);
63
- sourceToCjsDtsMap.set(sourceFileName, cjsFinalPath);
65
+ sourceToCjsDtsMap.set(sourceFileNameTS, cjsFinalPath);
66
+ sourceToCjsDtsMap.set(sourceFileNameTSX, cjsFinalPath);
64
67
  });
65
68
  for (const file of [
66
69
  ...sourceToCjsDtsMap.values(),
@@ -1 +1 @@
1
- {"version":3,"file":"callTypescript.js","sources":["../../../../../../src/tasks/buildTypesTask/callTypescript.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport * as fs from \"node:fs\";\nimport {\n inlineExtensionsMjs,\n inlineExtensionsCjs,\n} from \"./inlineExtensions.js\";\nimport { type PackageJson } from \"../../packageJson.js\";\nimport { getMinVersion, type TS } from \"../../detectModules.js\";\nimport { BuildError } from \"../../error.js\";\nimport { findTypingsPackages } from \"./findTypingsPackages.js\";\nimport { findTypingsNames } from \"./findTypingsNames.js\";\nimport { type Dirs } from \"../../resolveDirs.js\";\n\ntype BuildTypesOptions = {\n ts: TS;\n dirs: Dirs;\n packageJson: PackageJson;\n tsEntrypoints: string[];\n outDir: string;\n};\n\nfunction makeFileExists(outDir: string, filePath: string) {\n return (p: string) => {\n const dir = path.join(outDir, path.dirname(filePath));\n return fs.existsSync(path.join(dir, p));\n };\n}\n\nexport async function callTypescript({\n ts,\n dirs,\n tsEntrypoints,\n packageJson,\n}: BuildTypesOptions) {\n const { sourceDir, outDir, esmOutDir, cjsOutDir } = dirs;\n\n // <build d.ts>\n const sourceToCjsDtsMap = new Map<string, string>();\n const sourceToEsmDtsMap = new Map<string, string>();\n const program = ts.ts.createProgram(\n tsEntrypoints,\n ts.parsedConfig.options,\n ts.host,\n );\n program.emit(undefined, (fileName, data) => {\n // .d.ts for cjs because \"type\": \"commonjs\" in package.json\n // .d.mts for esm\n const relativePath = path.relative(sourceDir, fileName);\n const sourceFileName = fileName.replace(/\\.d\\.ts$/, \".ts\"); // Assuming source files have .ts extension\n\n const finalEsmPath = path.join(esmOutDir, relativePath);\n const esmFinalPath = finalEsmPath.replace(/\\.d\\.ts$/, \".d.mts\");\n sourceToEsmDtsMap.set(sourceFileName, esmFinalPath);\n fs.mkdirSync(path.dirname(esmFinalPath), { recursive: true });\n fs.writeFileSync(esmFinalPath, data);\n\n const finalCjsPath = path.join(cjsOutDir, relativePath);\n fs.mkdirSync(path.dirname(finalCjsPath), { recursive: true });\n const cjsFinalPath = finalCjsPath;\n fs.writeFileSync(cjsFinalPath, data);\n sourceToCjsDtsMap.set(sourceFileName, cjsFinalPath);\n });\n // </build d.ts>\n\n // <fix vscode typings>\n for (const file of [\n ...sourceToCjsDtsMap.values(),\n ...sourceToEsmDtsMap.values(),\n ]) {\n const content = fs.readFileSync(file, \"utf-8\");\n const relativePath = path.relative(outDir, file);\n if (file.endsWith(\".d.ts\")) {\n const transformedCode = inlineExtensionsCjs(\n ts.ts,\n content,\n makeFileExists(outDir, relativePath),\n );\n fs.writeFileSync(file, transformedCode);\n }\n if (file.endsWith(\".d.mts\")) {\n const transformedCode = inlineExtensionsMjs(\n ts.ts,\n content,\n makeFileExists(outDir, relativePath),\n );\n fs.writeFileSync(file, transformedCode);\n }\n }\n // </fix vscode typings>\n\n // <find all libraries names>\n const packages = new Set<string>();\n for (const sourceEntrypoint of tsEntrypoints) {\n const esmEntrypoint = sourceToEsmDtsMap.get(sourceEntrypoint);\n if (esmEntrypoint) {\n const localPackages = findTypingsNames(\n ts,\n esmEntrypoint,\n esmOutDir,\n \".d.mts\",\n );\n for (const p of localPackages) {\n packages.add(p);\n }\n }\n\n const cjsEntrypoint = sourceToCjsDtsMap.get(sourceEntrypoint);\n if (cjsEntrypoint) {\n const localPackages = findTypingsNames(\n ts,\n cjsEntrypoint,\n cjsOutDir,\n \".d.ts\",\n );\n for (const p of localPackages) {\n packages.add(p);\n }\n }\n }\n // </find all libraries names>\n\n // <check not installed typings libraries>\n const { missingTypings, existingTypingPackages } = findTypingsPackages(\n ts,\n packages,\n sourceDir,\n );\n for (const lib of existingTypingPackages) {\n if (\n getMinVersion(packageJson, lib, [\n \"optionalDependencies\",\n \"devDependencies\",\n ]) == null\n ) {\n missingTypings.add(lib);\n }\n }\n if (missingTypings.size > 0) {\n const libsList = [...missingTypings].map((x) => `\"${x}\"`).join(\", \");\n throw new BuildError(\n `The typings won't installed in bundled package: ${libsList}. Please install them into dependencies or peerDependencies.`,\n );\n }\n // </check not installed typings libraries>\n\n return {\n sourceToCjsDtsMap,\n sourceToEsmDtsMap,\n };\n}\n"],"names":["path","fs","inlineExtensionsCjs","inl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AAA,EACxB;AAEE,MAAA,eAAe,OAAO,GAAG;AAC3B,UAAM,WAAW,CAAC,GAAG,cAAc,EAAE,IAAI,CAAC,MAAM,IAAI,CAAC,GAAG,EAAE,KAAK,IAAI;AACnE,UAAM,IAAIC,MAAA;AAAA,MACR,mDAAmD,QAAQ;AAAA,IAC7D;AAAA,EAAA;AAIK,SAAA;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;;"}
1
+ {"version":3,"file":"callTypescript.js","sources":["../../../../../../src/tasks/buildTypesTask/callTypescript.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport * as fs from \"node:fs\";\nimport {\n inlineExtensionsMjs,\n inlineExtensionsCjs,\n} from \"./inlineExtensions.js\";\nimport { type PackageJson } from \"../../packageJson.js\";\nimport { getMinVersion, type TS } from \"../../detectModules.js\";\nimport { BuildError } from \"../../error.js\";\nimport { findTypingsPackages } from \"./findTypingsPackages.js\";\nimport { findTypingsNames } from \"./findTypingsNames.js\";\nimport { type Dirs } from \"../../resolveDirs.js\";\n\ntype BuildTypesOptions = {\n ts: TS;\n dirs: Dirs;\n packageJson: PackageJson;\n tsEntrypoints: string[];\n outDir: string;\n};\n\nfunction makeFileExists(outDir: string, filePath: string) {\n return (p: string) => {\n const dir = path.join(outDir, path.dirname(filePath));\n return fs.existsSync(path.join(dir, p));\n };\n}\n\nexport async function callTypescript({\n ts,\n dirs,\n tsEntrypoints,\n packageJson,\n}: BuildTypesOptions) {\n const { sourceDir, outDir, esmOutDir, cjsOutDir } = dirs;\n\n // <build d.ts>\n const sourceToCjsDtsMap = new Map<string, string>();\n const sourceToEsmDtsMap = new Map<string, string>();\n const program = ts.ts.createProgram(\n tsEntrypoints,\n ts.parsedConfig.options,\n ts.host,\n );\n program.emit(undefined, (fileName, data) => {\n // .d.ts for cjs because \"type\": \"commonjs\" in package.json\n // .d.mts for esm\n const relativePath = path.relative(sourceDir, fileName);\n // we create maps for ts and tsx because it can have any of these extensions\n // I don't want to detect the original ext,\n // so I've decided just create two maps and calculate the original file name outside of this function\n const sourceFileNameTS = fileName.replace(/\\.d\\.ts$/, \".ts\"); // Assuming source files have .ts extension\n const sourceFileNameTSX = fileName.replace(/\\.d\\.ts$/, \".tsx\"); // Assuming source files have .ts extension\n\n const finalEsmPath = path.join(esmOutDir, relativePath);\n const esmFinalPath = finalEsmPath.replace(/\\.d\\.ts$/, \".d.mts\");\n sourceToEsmDtsMap.set(sourceFileNameTS, esmFinalPath);\n sourceToEsmDtsMap.set(sourceFileNameTSX, esmFinalPath);\n fs.mkdirSync(path.dirname(esmFinalPath), { recursive: true });\n fs.writeFileSync(esmFinalPath, data);\n\n const finalCjsPath = path.join(cjsOutDir, relativePath);\n fs.mkdirSync(path.dirname(finalCjsPath), { recursive: true });\n const cjsFinalPath = finalCjsPath;\n fs.writeFileSync(cjsFinalPath, data);\n sourceToCjsDtsMap.set(sourceFileNameTS, cjsFinalPath);\n sourceToCjsDtsMap.set(sourceFileNameTSX, cjsFinalPath);\n });\n // </build d.ts>\n\n // <fix vscode typings>\n for (const file of [\n ...sourceToCjsDtsMap.values(),\n ...sourceToEsmDtsMap.values(),\n ]) {\n const content = fs.readFileSync(file, \"utf-8\");\n const relativePath = path.relative(outDir, file);\n if (file.endsWith(\".d.ts\")) {\n const transformedCode = inlineExtensionsCjs(\n ts.ts,\n content,\n makeFileExists(outDir, relativePath),\n );\n fs.writeFileSync(file, transformedCode);\n }\n if (file.endsWith(\".d.mts\")) {\n const transformedCode = inlineExtensionsMjs(\n ts.ts,\n content,\n makeFileExists(outDir, relativePath),\n );\n fs.writeFileSync(file, transformedCode);\n }\n }\n // </fix vscode typings>\n\n // <find all libraries names>\n const packages = new Set<string>();\n for (const sourceEntrypoint of tsEntrypoints) {\n const esmEntrypoint = sourceToEsmDtsMap.get(sourceEntrypoint);\n if (esmEntrypoint) {\n const localPackages = findTypingsNames(\n ts,\n esmEntrypoint,\n esmOutDir,\n \".d.mts\",\n );\n for (const p of localPackages) {\n packages.add(p);\n }\n }\n\n const cjsEntrypoint = sourceToCjsDtsMap.get(sourceEntrypoint);\n if (cjsEntrypoint) {\n const localPackages = findTypingsNames(\n ts,\n cjsEntrypoint,\n cjsOutDir,\n \".d.ts\",\n );\n for (const p of localPackages) {\n packages.add(p);\n }\n }\n }\n // </find all libraries names>\n\n // <check not installed typings libraries>\n const { missingTypings, existingTypingPackages } = findTypingsPackages(\n ts,\n packages,\n sourceDir,\n );\n for (const lib of existingTypingPackages) {\n if (\n getMinVersion(packageJson, lib, [\n \"optionalDependencies\",\n \"devDependencies\",\n ]) == null\n ) {\n missingTypings.add(lib);\n }\n }\n if (missingTypings.size > 0) {\n const libsList = [...missingTypings].map((x) => `\"${x}\"`).join(\", \");\n throw new BuildError(\n `The typings won't installed in bundled package: ${libsList}. Please install them into dependencies or peerDependencies.`,\n );\n }\n // </check not installed typings libraries>\n\n return {\n sourceToCjsDtsMap,\n sourceToEsmDtsMap,\n };\n}\n"],"names":["path","fs","inlineExtensionsCjs","inlineExtensionsMjs","findTypingsNames","findTypingsPackages","getMinVersion","BuildError"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,SAAS,eAAe,QAAgB,UAAkB;AACxD,SAAO,CAAC,MAAc;AACpB,UAAM,MAAMA,gBAAK,KAAK,QAAQA,gBAAK,QAAQ,QAAQ,CAAC;AACpD,WAAOC,cAAG,WAAWD,gBAAK,KAAK,KAAK,CAAC,CAAC;AAAA,EACxC;AACF;AAEA,eAAsB,eAAe;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAsB;AACpB,QAAM,EAAE,WAAW,QAAQ,WAAW,UAAc,IAAA;AAG9C,QAAA,wCAAwB,IAAoB;AAC5C,QAAA,wCAAwB,IAAoB;AAC5C,QAAA,UAAU,GAAG,GAAG;AAAA,IACpB;AAAA,IACA,GAAG,aAAa;AAAA,IAChB,GAAG;AAAA,EACL;AACA,UAAQ,KAAK,QAAW,CAAC,UAAU,SAAS;AAG1C,UAAM,e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aAAW,oBAAoB,eAAe;AACtC,UAAA,gBAAgB,kBAAkB,IAAI,gBAAgB;AAC5D,QAAI,eAAe;AACjB,YAAM,gBAAgBG,iBAAA;AAAA,QACpB;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AACA,iBAAW,KAAK,eAAe;AAC7B,iBAAS,IAAI,CAAC;AAAA,MAAA;AAAA,IAChB;AAGI,UAAA,gBAAgB,kBAAkB,IAAI,gBAAgB;AAC5D,QAAI,eAAe;AACjB,YAAM,gBAAgBA,iBAAA;AAAA,QACpB;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AACA,iBAAW,KAAK,eAAe;AAC7B,iBAAS,IAAI,CAAC;AAAA,MAAA;AAAA,IAChB;AAAA,EACF;AAKI,QAAA,EAAE,gBAAgB,uBAAA,IAA2BC,oBAAA;AAAA,IACjD;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,aAAW,OAAO,wBAAwB;AAEtC,QAAAC,cAAA,cAAc,aAAa,KAAK;AAAA,MAC9B;AAAA,MACA;AAAA,IACD,CAAA,KAAK,MACN;AACA,qBAAe,IAAI,GAAG;AAAA,IAAA;AAAA,EACxB;AAEE,MAAA,eAAe,OAAO,GAAG;AAC3B,UAAM,WAAW,CAAC,GAAG,cAAc,EAAE,IAAI,CAAC,MAAM,IAAI,CAAC,GAAG,EAAE,KAAK,IAAI;AACnE,UAAM,IAAIC,MAAA;AAAA,MACR,mDAAmD,QAAQ;AAAA,IAC7D;AAAA,EAAA;AAIK,SAAA;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;;"}
@@ -13,7 +13,7 @@ async function buildTypesTask({
13
13
  }) {
14
14
  const { outDir } = dirs;
15
15
  const tsEntrypoints = [...entrypoints.values()].filter(
16
- (entry) => entry.endsWith(".ts")
16
+ (entry) => entry.endsWith(".ts") || entry.endsWith(".tsx")
17
17
  );
18
18
  const reversedEntrypoints = reverseMap(entrypoints);
19
19
  const entrypointToEsDtsMap = /* @__PURE__ */ new Map();
@@ -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 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;"}
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\") || entry.endsWith(\".tsx\"),\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,KAAK,MAAM,SAAS,MAAM;AAAA,EAChD;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;"}
@@ -30,17 +30,20 @@ async function callTypescript({
30
30
  );
31
31
  program.emit(void 0, (fileName, data) => {
32
32
  const relativePath = path.relative(sourceDir, fileName);
33
- const sourceFileName = fileName.replace(/\.d\.ts$/, ".ts");
33
+ const sourceFileNameTS = fileName.replace(/\.d\.ts$/, ".ts");
34
+ const sourceFileNameTSX = fileName.replace(/\.d\.ts$/, ".tsx");
34
35
  const finalEsmPath = path.join(esmOutDir, relativePath);
35
36
  const esmFinalPath = finalEsmPath.replace(/\.d\.ts$/, ".d.mts");
36
- sourceToEsmDtsMap.set(sourceFileName, esmFinalPath);
37
+ sourceToEsmDtsMap.set(sourceFileNameTS, esmFinalPath);
38
+ sourceToEsmDtsMap.set(sourceFileNameTSX, esmFinalPath);
37
39
  fs.mkdirSync(path.dirname(esmFinalPath), { recursive: true });
38
40
  fs.writeFileSync(esmFinalPath, data);
39
41
  const finalCjsPath = path.join(cjsOutDir, relativePath);
40
42
  fs.mkdirSync(path.dirname(finalCjsPath), { recursive: true });
41
43
  const cjsFinalPath = finalCjsPath;
42
44
  fs.writeFileSync(cjsFinalPath, data);
43
- sourceToCjsDtsMap.set(sourceFileName, cjsFinalPath);
45
+ sourceToCjsDtsMap.set(sourceFileNameTS, cjsFinalPath);
46
+ sourceToCjsDtsMap.set(sourceFileNameTSX, cjsFinalPath);
44
47
  });
45
48
  for (const file of [
46
49
  ...sourceToCjsDtsMap.values(),
@@ -1 +1 @@
1
- {"version":3,"file":"callTypescript.mjs","sources":["../../../../../../src/tasks/buildTypesTask/callTypescript.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport * as fs from \"node:fs\";\nimport {\n inlineExtensionsMjs,\n inlineExtensionsCjs,\n} from \"./inlineExtensions.js\";\nimport { type PackageJson } from \"../../packageJson.js\";\nimport { getMinVersion, type TS } from \"../../detectModules.js\";\nimport { BuildError } from \"../../error.js\";\nimport { findTypingsPackages } from \"./findTypingsPackages.js\";\nimport { findTypingsNames } from \"./findTypingsNames.js\";\nimport { type Dirs } from \"../../resolveDirs.js\";\n\ntype BuildTypesOptions = {\n ts: TS;\n dirs: Dirs;\n packageJson: PackageJson;\n tsEntrypoints: string[];\n outDir: string;\n};\n\nfunction makeFileExists(outDir: string, filePath: string) {\n return (p: string) => {\n const dir = path.join(outDir, path.dirname(filePath));\n return fs.existsSync(path.join(dir, p));\n };\n}\n\nexport async function callTypescript({\n ts,\n dirs,\n tsEntrypoints,\n packageJson,\n}: BuildTypesOptions) {\n const { sourceDir, outDir, esmOutDir, cjsOutDir } = dirs;\n\n // <build d.ts>\n const sourceToCjsDtsMap = new Map<string, string>();\n const sourceToEsmDtsMap = new Map<string, string>();\n const program = ts.ts.createProgram(\n tsEntrypoints,\n ts.parsedConfig.options,\n ts.host,\n );\n program.emit(undefined, (fileName, data) => {\n // .d.ts for cjs because \"type\": \"commonjs\" in package.json\n // .d.mts for esm\n const relativePath = path.relative(sourceDir, fileName);\n const sourceFileName = fileName.replace(/\\.d\\.ts$/, \".ts\"); // Assuming source files have .ts extension\n\n const finalEsmPath = path.join(esmOutDir, relativePath);\n const esmFinalPath = finalEsmPath.replace(/\\.d\\.ts$/, \".d.mts\");\n sourceToEsmDtsMap.set(sourceFileName, esmFinalPath);\n fs.mkdirSync(path.dirname(esmFinalPath), { recursive: true });\n fs.writeFileSync(esmFinalPath, data);\n\n const finalCjsPath = path.join(cjsOutDir, relativePath);\n fs.mkdirSync(path.dirname(finalCjsPath), { recursive: true });\n const cjsFinalPath = finalCjsPath;\n fs.writeFileSync(cjsFinalPath, data);\n sourceToCjsDtsMap.set(sourceFileName, cjsFinalPath);\n });\n // </build d.ts>\n\n // <fix vscode typings>\n for (const file of [\n ...sourceToCjsDtsMap.values(),\n ...sourceToEsmDtsMap.values(),\n ]) {\n const content = fs.readFileSync(file, \"utf-8\");\n const relativePath = path.relative(outDir, file);\n if (file.endsWith(\".d.ts\")) {\n const transformedCode = inlineExtensionsCjs(\n ts.ts,\n content,\n makeFileExists(outDir, relativePath),\n );\n fs.writeFileSync(file, transformedCode);\n }\n if (file.endsWith(\".d.mts\")) {\n const transformedCode = inlineExtensionsMjs(\n ts.ts,\n content,\n makeFileExists(outDir, relativePath),\n );\n fs.writeFileSync(file, transformedCode);\n }\n }\n // </fix vscode typings>\n\n // <find all libraries names>\n const packages = new Set<string>();\n for (const sourceEntrypoint of tsEntrypoints) {\n const esmEntrypoint = sourceToEsmDtsMap.get(sourceEntrypoint);\n if (esmEntrypoint) {\n const localPackages = findTypingsNames(\n ts,\n esmEntrypoint,\n esmOutDir,\n \".d.mts\",\n );\n for (const p of localPackages) {\n packages.add(p);\n }\n }\n\n const cjsEntrypoint = sourceToCjsDtsMap.get(sourceEntrypoint);\n if (cjsEntrypoint) {\n const localPackages = findTypingsNames(\n ts,\n cjsEntrypoint,\n cjsOutDir,\n \".d.ts\",\n );\n for (const p of localPackages) {\n packages.add(p);\n }\n }\n }\n // </find all libraries names>\n\n // <check not installed typings libraries>\n const { missingTypings, existingTypingPackages } = findTypingsPackages(\n ts,\n packages,\n sourceDir,\n );\n for (const lib of existingTypingPackages) {\n if (\n getMinVersion(packageJson, lib, [\n \"optionalDependencies\",\n \"devDependencies\",\n ]) == null\n ) {\n missingTypings.add(lib);\n }\n }\n if (missingTypings.size > 0) {\n const libsList = [...missingTypings].map((x) => `\"${x}\"`).join(\", \");\n throw new BuildError(\n `The typings won't installed in bundled package: ${libsList}. Please install them into dependencies or peerDependencies.`,\n );\n }\n // </check not installed typings libraries>\n\n return {\n sourceToCjsDtsMap,\n sourceToEsmDtsMap,\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;AAqBA,SAAS,eAAe,QAAgB,UAAkB;AACxD,SAAO,CAAC,MAAc;AACpB,UAAM,MAAM,KAAK,KAAK,QAAQ,KAAK,QAAQ,QAAQ,CAAC;AACpD,WAAO,GAAG,WAAW,KAAK,KAAK,KAAK,CAAC,CAAC;AAAA,EACxC;AACF;AAEA,eAAsB,eAAe;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAsB;AACpB,QAAM,EAAE,WAAW,QAAQ,WAAW,UAAc,IAAA;AAG9C,QAAA,wCAAwB,IAAoB;AAC5C,QAAA,wCAAwB,IAAoB;AAC5C,QAAA,UAAU,GAAG,GAAG;AAAA,IACpB;AAAA,IACA,GAAG,aAAa;AAAA,IAChB,GAAG;AAAA,EACL;A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AAA,QACpB;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AACA,iBAAW,KAAK,eAAe;AAC7B,iBAAS,IAAI,CAAC;AAAA,MAAA;AAAA,IAChB;AAGI,UAAA,gBAAgB,kBAAkB,IAAI,gBAAgB;AAC5D,QAAI,eAAe;AACjB,YAAM,gBAAgB;AAAA,QACpB;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AACA,iBAAW,KAAK,eAAe;AAC7B,iBAAS,IAAI,CAAC;AAAA,MAAA;AAAA,IAChB;AAAA,EACF;AAKI,QAAA,EAAE,gBAAgB,uBAAA,IAA2B;AAAA,IACjD;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,aAAW,OAAO,wBAAwB;AAEtC,QAAA,cAAc,aAAa,KAAK;AAAA,MAC9B;AAAA,MACA;AAAA,IACD,CAAA,KAAK,MACN;AACA,qBAAe,IAAI,GAAG;AAAA,IAAA;AAAA,EACxB;AAEE,MAAA,eAAe,OAAO,GAAG;AAC3B,UAAM,WAAW,CAAC,GAAG,cAAc,EAAE,IAAI,CAAC,MAAM,IAAI,CAAC,GAAG,EAAE,KAAK,IAAI;AACnE,UAAM,IAAI;AAAA,MACR,mDAAmD,QAAQ;AAAA,IAC7D;AAAA,EAAA;AAIK,SAAA;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;"}
1
+ {"version":3,"file":"callTypescript.mjs","sources":["../../../../../../src/tasks/buildTypesTask/callTypescript.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport * as fs from \"node:fs\";\nimport {\n inlineExtensionsMjs,\n inlineExtensionsCjs,\n} from \"./inlineExtensions.js\";\nimport { type PackageJson } from \"../../packageJson.js\";\nimport { getMinVersion, type TS } from \"../../detectModules.js\";\nimport { BuildError } from \"../../error.js\";\nimport { findTypingsPackages } from \"./findTypingsPackages.js\";\nimport { findTypingsNames } from \"./findTypingsNames.js\";\nimport { type Dirs } from \"../../resolveDirs.js\";\n\ntype BuildTypesOptions = {\n ts: TS;\n dirs: Dirs;\n packageJson: PackageJson;\n tsEntrypoints: string[];\n outDir: string;\n};\n\nfunction makeFileExists(outDir: string, filePath: string) {\n return (p: string) => {\n const dir = path.join(outDir, path.dirname(filePath));\n return fs.existsSync(path.join(dir, p));\n };\n}\n\nexport async function callTypescript({\n ts,\n dirs,\n tsEntrypoints,\n packageJson,\n}: BuildTypesOptions) {\n const { sourceDir, outDir, esmOutDir, cjsOutDir } = dirs;\n\n // <build d.ts>\n const sourceToCjsDtsMap = new Map<string, string>();\n const sourceToEsmDtsMap = new Map<string, string>();\n const program = ts.ts.createProgram(\n tsEntrypoints,\n ts.parsedConfig.options,\n ts.host,\n );\n program.emit(undefined, (fileName, data) => {\n // .d.ts for cjs because \"type\": \"commonjs\" in package.json\n // .d.mts for esm\n const relativePath = path.relative(sourceDir, fileName);\n // we create maps for ts and tsx because it can have any of these extensions\n // I don't want to detect the original ext,\n // so I've decided just create two maps and calculate the original file name outside of this function\n const sourceFileNameTS = fileName.replace(/\\.d\\.ts$/, \".ts\"); // Assuming source files have .ts extension\n const sourceFileNameTSX = fileName.replace(/\\.d\\.ts$/, \".tsx\"); // Assuming source files have .ts extension\n\n const finalEsmPath = path.join(esmOutDir, relativePath);\n const esmFinalPath = finalEsmPath.replace(/\\.d\\.ts$/, \".d.mts\");\n sourceToEsmDtsMap.set(sourceFileNameTS, esmFinalPath);\n sourceToEsmDtsMap.set(sourceFileNameTSX, esmFinalPath);\n fs.mkdirSync(path.dirname(esmFinalPath), { recursive: true });\n fs.writeFileSync(esmFinalPath, data);\n\n const finalCjsPath = path.join(cjsOutDir, relativePath);\n fs.mkdirSync(path.dirname(finalCjsPath), { recursive: true });\n const cjsFinalPath = finalCjsPath;\n fs.writeFileSync(cjsFinalPath, data);\n sourceToCjsDtsMap.set(sourceFileNameTS, cjsFinalPath);\n sourceToCjsDtsMap.set(sourceFileNameTSX, cjsFinalPath);\n });\n // </build d.ts>\n\n // <fix vscode typings>\n for (const file of [\n ...sourceToCjsDtsMap.values(),\n ...sourceToEsmDtsMap.values(),\n ]) {\n const content = fs.readFileSync(file, \"utf-8\");\n const relativePath = path.relative(outDir, file);\n if (file.endsWith(\".d.ts\")) {\n const transformedCode = inlineExtensionsCjs(\n ts.ts,\n content,\n makeFileExists(outDir, relativePath),\n );\n fs.writeFileSync(file, transformedCode);\n }\n if (file.endsWith(\".d.mts\")) {\n const transformedCode = inlineExtensionsMjs(\n ts.ts,\n content,\n makeFileExists(outDir, relativePath),\n );\n fs.writeFileSync(file, transformedCode);\n }\n }\n // </fix vscode typings>\n\n // <find all libraries names>\n const packages = new Set<string>();\n for (const sourceEntrypoint of tsEntrypoints) {\n const esmEntrypoint = sourceToEsmDtsMap.get(sourceEntrypoint);\n if (esmEntrypoint) {\n const localPackages = findTypingsNames(\n ts,\n esmEntrypoint,\n esmOutDir,\n \".d.mts\",\n );\n for (const p of localPackages) {\n packages.add(p);\n }\n }\n\n const cjsEntrypoint = sourceToCjsDtsMap.get(sourceEntrypoint);\n if (cjsEntrypoint) {\n const localPackages = findTypingsNames(\n ts,\n cjsEntrypoint,\n cjsOutDir,\n \".d.ts\",\n );\n for (const p of localPackages) {\n packages.add(p);\n }\n }\n }\n // </find all libraries names>\n\n // <check not installed typings libraries>\n const { missingTypings, existingTypingPackages } = findTypingsPackages(\n ts,\n packages,\n sourceDir,\n );\n for (const lib of existingTypingPackages) {\n if (\n getMinVersion(packageJson, lib, [\n \"optionalDependencies\",\n \"devDependencies\",\n ]) == null\n ) {\n missingTypings.add(lib);\n }\n }\n if (missingTypings.size > 0) {\n const libsList = [...missingTypings].map((x) => `\"${x}\"`).join(\", \");\n throw new BuildError(\n `The typings won't installed in bundled package: ${libsList}. Please install them into dependencies or peerDependencies.`,\n );\n }\n // </check not installed typings libraries>\n\n return {\n sourceToCjsDtsMap,\n sourceToEsmDtsMap,\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;AAqBA,SAAS,eAAe,QAAgB,UAAkB;AACxD,SAAO,CAAC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GAAG,EAAE,KAAK,IAAI;AACnE,UAAM,IAAI;AAAA,MACR,mDAAmD,QAAQ;AAAA,IAC7D;AAAA,EAAA;AAIK,SAAA;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "smartbundle",
3
3
  "type": "commonjs",
4
- "version": "0.13.0",
4
+ "version": "0.13.1-alpha.0",
5
5
  "bin": {
6
6
  "smartbundle": "__bin__/smartbundle.js"
7
7
  },