@savvy-web/rslib-builder 0.2.0 → 0.2.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/README.md CHANGED
@@ -50,7 +50,7 @@ Extend the provided tsconfig for optimal settings:
50
50
  ```jsonc
51
51
  // tsconfig.json
52
52
  {
53
- "extends": "@savvy-web/rslib-builder/tsconfig/node/ecma/lib.json",
53
+ "extends": "@savvy-web/rslib-builder/tsconfig/ecma/lib.json",
54
54
  "compilerOptions": {
55
55
  "outDir": "dist"
56
56
  }
package/index.d.ts CHANGED
@@ -698,6 +698,10 @@ export declare class PackageJsonTransformer {
698
698
  /**
699
699
  * Transforms the bin field for build output.
700
700
  *
701
+ * @remarks
702
+ * TypeScript bin entries are compiled to `./bin/{command-name}.js` by RSlib.
703
+ * Non-TypeScript entries (shell scripts, compiled JS) are preserved as-is.
704
+ *
701
705
  * @param bin - The bin field from package.json
702
706
  * @returns The transformed bin field
703
707
  */
package/index.js CHANGED
@@ -269,7 +269,7 @@ var root_namespaceObject = JSON.parse('{"$schema":"https://json.schemastore.org/
269
269
  const requireCJS = createRequire(import.meta.url);
270
270
  const jsonImports = new Map([
271
271
  [
272
- (0, external_node_path_.join)(import.meta.dirname, "../public/tsconfig/node/ecma/lib.json"),
272
+ (0, external_node_path_.join)(import.meta.dirname, "../public/tsconfig/ecma/lib.json"),
273
273
  lib_namespaceObject
274
274
  ],
275
275
  [
@@ -386,7 +386,7 @@ class LibraryTSConfigFile extends TSConfigFile {
386
386
  }
387
387
  }
388
388
  const Root = new TSConfigFile("Root configuration for workspace setup", (0, external_node_path_.join)(import.meta.dirname, "../public/tsconfig/root.json"));
389
- const NodeEcmaLib = new LibraryTSConfigFile("ECMAScript library build configuration", (0, external_node_path_.join)(import.meta.dirname, "../public/tsconfig/node/ecma/lib.json"));
389
+ const NodeEcmaLib = new LibraryTSConfigFile("ECMAScript library build configuration", (0, external_node_path_.join)(import.meta.dirname, "../public/tsconfig/ecma/lib.json"));
390
390
  const TSConfigs = {
391
391
  root: Root,
392
392
  node: {
@@ -900,36 +900,19 @@ function runTsgo(options) {
900
900
  context.compilation.emitAsset(apiModelFilename, apiModelSource);
901
901
  if (filesArray) filesArray.add(`!${apiModelFilename}`);
902
902
  core_logger.info(`${picocolors.dim(`[${envId}]`)} Emitted API model: ${apiModelFilename} (excluded from npm publish)`);
903
- const isCI = "true" === process.env.GITHUB_ACTIONS || "true" === process.env.CI;
904
903
  const localPaths = "object" == typeof options.apiModel ? options.apiModel.localPaths : void 0;
905
- if (localPaths && localPaths.length > 0 && !isCI) for (const localPath of localPaths){
906
- const resolvedPath = (0, external_node_path_.join)(cwd, localPath);
907
- const parentDir = (0, external_node_path_.dirname)(resolvedPath);
908
- if (!existsSync(parentDir)) {
909
- core_logger.warn(`${picocolors.dim(`[${envId}]`)} Skipping local path: parent directory does not exist: ${parentDir}`);
910
- continue;
911
- }
912
- await mkdir(resolvedPath, {
913
- recursive: true
904
+ const isCI = "true" === process.env.GITHUB_ACTIONS || "true" === process.env.CI;
905
+ if (localPaths && localPaths.length > 0 && !isCI) {
906
+ const tsdocMetadataOption = "object" == typeof options.apiModel ? options.apiModel.tsdocMetadata : void 0;
907
+ const localTsdocFilename = "object" == typeof tsdocMetadataOption && tsdocMetadataOption.filename ? tsdocMetadataOption.filename : "tsdoc-metadata.json";
908
+ api.expose("dts-local-paths-data", {
909
+ localPaths,
910
+ apiModelFilename,
911
+ localTsdocFilename,
912
+ hasTsdocMetadata: !!tsdocMetadataPath,
913
+ cwd,
914
+ distPath: `dist/${envId}`
914
915
  });
915
- const apiModelDestPath = (0, external_node_path_.join)(resolvedPath, apiModelFilename);
916
- await writeFile(apiModelDestPath, apiModelContent, "utf-8");
917
- if (tsdocMetadataPath) {
918
- const tsdocMetadataOption = "object" == typeof options.apiModel ? options.apiModel.tsdocMetadata : void 0;
919
- const localTsdocFilename = "object" == typeof tsdocMetadataOption && tsdocMetadataOption.filename ? tsdocMetadataOption.filename : "tsdoc-metadata.json";
920
- const tsdocContent = await promises_readFile(tsdocMetadataPath, "utf-8");
921
- const tsdocDestPath = (0, external_node_path_.join)(resolvedPath, localTsdocFilename);
922
- await writeFile(tsdocDestPath, tsdocContent, "utf-8");
923
- }
924
- const packageJsonAsset = context.compilation.assets["package.json"];
925
- if (packageJsonAsset) {
926
- const rawContent = "function" == typeof packageJsonAsset.source ? packageJsonAsset.source() : packageJsonAsset.source;
927
- const packageJsonContent = "string" == typeof rawContent ? rawContent : rawContent instanceof Buffer ? rawContent.toString("utf-8") : String(rawContent);
928
- const packageJsonDestPath = (0, external_node_path_.join)(resolvedPath, "package.json");
929
- await writeFile(packageJsonDestPath, packageJsonContent, "utf-8");
930
- }
931
- const copiedFiles = tsdocMetadataPath ? "API model, tsdoc-metadata.json, and package.json" : "API model and package.json";
932
- core_logger.info(`${picocolors.dim(`[${envId}]`)} Copied ${copiedFiles} to: ${localPath}`);
933
916
  }
934
917
  }
935
918
  if (tsdocMetadataPath) {
@@ -1002,6 +985,50 @@ function runTsgo(options) {
1002
985
  } else if (assetName.endsWith(".d.ts.map")) assetsToDelete.push(assetName);
1003
986
  for (const assetName of assetsToDelete)delete compiler.compilation.assets[assetName];
1004
987
  });
988
+ api.onCloseBuild(async ()=>{
989
+ const localPathsData = api.useExposed("dts-local-paths-data");
990
+ if (!localPathsData) return;
991
+ const { localPaths, apiModelFilename, localTsdocFilename, hasTsdocMetadata, cwd, distPath } = localPathsData;
992
+ const distDir = (0, external_node_path_.join)(cwd, distPath);
993
+ for (const localPath of localPaths){
994
+ const resolvedPath = (0, external_node_path_.join)(cwd, localPath);
995
+ const parentDir = (0, external_node_path_.dirname)(resolvedPath);
996
+ if (!existsSync(parentDir)) {
997
+ core_logger.warn(`Skipping local path: parent directory does not exist: ${parentDir}`);
998
+ continue;
999
+ }
1000
+ const filesToCopy = [];
1001
+ const apiModelSrc = (0, external_node_path_.join)(distDir, apiModelFilename);
1002
+ if (existsSync(apiModelSrc)) filesToCopy.push({
1003
+ src: apiModelSrc,
1004
+ dest: (0, external_node_path_.join)(resolvedPath, apiModelFilename),
1005
+ name: apiModelFilename
1006
+ });
1007
+ if (hasTsdocMetadata) {
1008
+ const tsdocSrc = (0, external_node_path_.join)(distDir, localTsdocFilename);
1009
+ if (existsSync(tsdocSrc)) filesToCopy.push({
1010
+ src: tsdocSrc,
1011
+ dest: (0, external_node_path_.join)(resolvedPath, localTsdocFilename),
1012
+ name: localTsdocFilename
1013
+ });
1014
+ }
1015
+ const packageJsonSrc = (0, external_node_path_.join)(distDir, "package.json");
1016
+ if (existsSync(packageJsonSrc)) filesToCopy.push({
1017
+ src: packageJsonSrc,
1018
+ dest: (0, external_node_path_.join)(resolvedPath, "package.json"),
1019
+ name: "package.json"
1020
+ });
1021
+ await mkdir(resolvedPath, {
1022
+ recursive: true
1023
+ });
1024
+ for (const file of filesToCopy){
1025
+ const content = await promises_readFile(file.src, "utf-8");
1026
+ await writeFile(file.dest, content, "utf-8");
1027
+ }
1028
+ const fileNames = filesToCopy.map((f)=>f.name).join(", ");
1029
+ core_logger.info(`Copied ${fileNames} to: ${localPath}`);
1030
+ }
1031
+ });
1005
1032
  }
1006
1033
  };
1007
1034
  };
@@ -1287,9 +1314,9 @@ class PackageJsonTransformer {
1287
1314
  }
1288
1315
  transformExportPath(path) {
1289
1316
  let transformedPath = path;
1317
+ if (transformedPath.startsWith("./src/")) transformedPath = `./${transformedPath.slice(6)}`;
1290
1318
  if (transformedPath.startsWith("./exports/")) transformedPath = `./${transformedPath.slice(10)}`;
1291
- else if (transformedPath.startsWith("./public/")) transformedPath = `./${transformedPath.slice(9)}`;
1292
- else if (transformedPath.startsWith("./src/")) transformedPath = `./${transformedPath.slice(6)}`;
1319
+ if (transformedPath.startsWith("./public/")) transformedPath = `./${transformedPath.slice(9)}`;
1293
1320
  if (this.options.processTSExports) {
1294
1321
  const { collapseIndex } = this.options;
1295
1322
  if (collapseIndex && transformedPath.endsWith("/index.ts") && "./index.ts" !== transformedPath) transformedPath = `${transformedPath.slice(0, -9)}.js`;
@@ -1315,10 +1342,14 @@ class PackageJsonTransformer {
1315
1342
  return exports;
1316
1343
  }
1317
1344
  transformBin(bin) {
1318
- if ("string" == typeof bin) return this.transformExportPath(bin);
1345
+ if ("string" == typeof bin) {
1346
+ if (bin.endsWith(".ts") || bin.endsWith(".tsx")) return "./bin/cli.js";
1347
+ return bin;
1348
+ }
1319
1349
  if (bin && "object" == typeof bin) {
1320
1350
  const transformed = {};
1321
- for (const [command, path] of Object.entries(bin))if (void 0 !== path) transformed[command] = this.transformExportPath(path);
1351
+ for (const [command, path] of Object.entries(bin))if (void 0 !== path) if (path.endsWith(".ts") || path.endsWith(".tsx")) transformed[command] = `./bin/${command}.js`;
1352
+ else transformed[command] = path;
1322
1353
  return transformed;
1323
1354
  }
1324
1355
  return bin;
@@ -1400,9 +1431,9 @@ class PackageJsonTransformer {
1400
1431
  }
1401
1432
  function transformExportPath(path, processTSExports = true, collapseIndex = false) {
1402
1433
  let transformedPath = path;
1434
+ if (transformedPath.startsWith("./src/")) transformedPath = `./${transformedPath.slice(6)}`;
1403
1435
  if (transformedPath.startsWith("./exports/")) transformedPath = `./${transformedPath.slice(10)}`;
1404
- else if (transformedPath.startsWith("./public/")) transformedPath = `./${transformedPath.slice(9)}`;
1405
- else if (transformedPath.startsWith("./src/")) transformedPath = `./${transformedPath.slice(6)}`;
1436
+ if (transformedPath.startsWith("./public/")) transformedPath = `./${transformedPath.slice(9)}`;
1406
1437
  if (processTSExports) {
1407
1438
  if (collapseIndex && transformedPath.endsWith("/index.ts") && "./index.ts" !== transformedPath) transformedPath = `${transformedPath.slice(0, -9)}.js`;
1408
1439
  else if (collapseIndex && transformedPath.endsWith("/index.tsx") && "./index.tsx" !== transformedPath) transformedPath = `${transformedPath.slice(0, -10)}.js`;
@@ -1416,11 +1447,15 @@ function createTypePath(jsPath, collapseIndex = true) {
1416
1447
  if (jsPath.endsWith(".js")) return `${jsPath.slice(0, -3)}.d.ts`;
1417
1448
  return `${jsPath}.d.ts`;
1418
1449
  }
1419
- function transformPackageBin(bin, processTSExports = true) {
1420
- if ("string" == typeof bin) return transformExportPath(bin, processTSExports);
1450
+ function transformPackageBin(bin, _processTSExports = true) {
1451
+ if ("string" == typeof bin) {
1452
+ if (bin.endsWith(".ts") || bin.endsWith(".tsx")) return "./bin/cli.js";
1453
+ return bin;
1454
+ }
1421
1455
  if (bin && "object" == typeof bin) {
1422
1456
  const transformed = {};
1423
- for (const [command, path] of Object.entries(bin))if (void 0 !== path) transformed[command] = transformExportPath(path, processTSExports);
1457
+ for (const [command, path] of Object.entries(bin))if (void 0 !== path) if (path.endsWith(".ts") || path.endsWith(".tsx")) transformed[command] = `./bin/${command}.js`;
1458
+ else transformed[command] = path;
1424
1459
  return transformed;
1425
1460
  }
1426
1461
  return bin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@savvy-web/rslib-builder",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "private": false,
5
5
  "description": "RSlib-based build system for Node.js libraries with automatic package.json transformation, TypeScript declaration bundling, and multi-target support",
6
6
  "homepage": "https://github.com/savvy-web/rslib-builder",
@@ -24,18 +24,14 @@
24
24
  "types": "./index.d.ts",
25
25
  "import": "./index.js"
26
26
  },
27
- "./tsconfig/root.json": "./public/tsconfig/root.json",
28
- "./tsconfig/node/ecma/lib.json": "./public/tsconfig/node/ecma/lib.json",
29
- "./tsconfig/node/ecma/lib-compat.json": "./public/tsconfig/node/ecma/lib-compat.json",
30
- "./tsconfig/node/ecma/bundle.json": "./public/tsconfig/node/ecma/bundle.json",
31
- "./tsconfig/node/ecma/bundleless.json": "./public/tsconfig/node/ecma/bundleless.json"
27
+ "./tsconfig/root.json": "./tsconfig/root.json",
28
+ "./tsconfig/ecma/lib.json": "./tsconfig/ecma/lib.json"
32
29
  },
33
30
  "dependencies": {
34
31
  "@microsoft/tsdoc": "^0.16.0",
35
32
  "@microsoft/tsdoc-config": "^0.18.0",
36
33
  "@pnpm/exportable-manifest": "^1000.3.0",
37
34
  "glob": "^13.0.0",
38
- "markdownlint-cli2": "^0.20.0",
39
35
  "picocolors": "^1.1.1",
40
36
  "sort-package-json": "^3.6.0",
41
37
  "tmp": "^0.2.5",
@@ -59,20 +55,6 @@
59
55
  "optional": false
60
56
  }
61
57
  },
62
- "devEngines": {
63
- "packageManager": {
64
- "name": "pnpm",
65
- "version": "10.28.0",
66
- "onFail": "ignore"
67
- },
68
- "runtime": [
69
- {
70
- "name": "node",
71
- "version": "24.11.0",
72
- "onFail": "ignore"
73
- }
74
- ]
75
- },
76
58
  "files": [
77
59
  "!rslib-builder.api.json",
78
60
  "LICENSE",
@@ -81,7 +63,7 @@
81
63
  "index.js",
82
64
  "package.json",
83
65
  "rslib-runtime.js",
84
- "tsconfig/node/ecma/lib.json",
66
+ "tsconfig/ecma/lib.json",
85
67
  "tsconfig/root.json",
86
68
  "tsdoc-metadata.json"
87
69
  ]
File without changes