@yaonyan/jsr2npm 0.1.3 → 0.1.4

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
@@ -151,7 +151,6 @@ The script automates these steps:
151
151
 
152
152
  ## Requirements
153
153
 
154
- - [Deno](https://deno.land/)
155
154
  - [Node.js](https://nodejs.org/) (which includes `npx`)
156
155
 
157
156
  ## Usage
package/bin/jsr2npm.mjs CHANGED
@@ -8,9 +8,10 @@ var __export = (target, all) => {
8
8
  };
9
9
 
10
10
  // node_modules/@yao/jsr2npm/config.js
11
+ import { readFile } from "node:fs/promises";
11
12
  async function loadConfig(configPath) {
12
13
  try {
13
- const content = await Deno.readTextFile(configPath);
14
+ const content = await readFile(configPath, "utf-8");
14
15
  return JSON.parse(content);
15
16
  } catch {
16
17
  return null;
@@ -1228,9 +1229,9 @@ function throwIfNotDirectory(fileInfo) {
1228
1229
  // node_modules/@jsr/std__fs/ensure_file.js
1229
1230
  async function ensureFile(filePath) {
1230
1231
  try {
1231
- const stat = await Deno.lstat(filePath);
1232
- if (!stat.isFile) {
1233
- throw new Error(`Failed to ensure file exists: expected 'file', got '${getFileInfoType(stat)}'`);
1232
+ const stat4 = await Deno.lstat(filePath);
1233
+ if (!stat4.isFile) {
1234
+ throw new Error(`Failed to ensure file exists: expected 'file', got '${getFileInfoType(stat4)}'`);
1234
1235
  }
1235
1236
  } catch (err) {
1236
1237
  if (err instanceof Deno.errors.NotFound) {
@@ -1243,9 +1244,9 @@ async function ensureFile(filePath) {
1243
1244
  }
1244
1245
  function ensureFileSync(filePath) {
1245
1246
  try {
1246
- const stat = Deno.lstatSync(filePath);
1247
- if (!stat.isFile) {
1248
- throw new Error(`Failed to ensure file exists: expected 'file', got '${getFileInfoType(stat)}'`);
1247
+ const stat4 = Deno.lstatSync(filePath);
1248
+ if (!stat4.isFile) {
1249
+ throw new Error(`Failed to ensure file exists: expected 'file', got '${getFileInfoType(stat4)}'`);
1249
1250
  }
1250
1251
  } catch (err) {
1251
1252
  if (err instanceof Deno.errors.NotFound) {
@@ -5382,16 +5383,16 @@ function parseArgs6(args) {
5382
5383
  // node_modules/@jsr/std__fs/exists.js
5383
5384
  async function exists(path, options) {
5384
5385
  try {
5385
- const stat = await Deno.stat(path);
5386
+ const stat4 = await Deno.stat(path);
5386
5387
  if (options && (options.isReadable || options.isDirectory || options.isFile)) {
5387
5388
  if (options.isDirectory && options.isFile) {
5388
5389
  throw new TypeError("ExistsOptions.options.isDirectory and ExistsOptions.options.isFile must not be true together");
5389
5390
  }
5390
- if (options.isDirectory && !stat.isDirectory || options.isFile && !stat.isFile) {
5391
+ if (options.isDirectory && !stat4.isDirectory || options.isFile && !stat4.isFile) {
5391
5392
  return false;
5392
5393
  }
5393
5394
  if (options.isReadable) {
5394
- return fileIsReadable(stat);
5395
+ return fileIsReadable(stat4);
5395
5396
  }
5396
5397
  }
5397
5398
  return true;
@@ -5412,16 +5413,16 @@ async function exists(path, options) {
5412
5413
  }
5413
5414
  function existsSync(path, options) {
5414
5415
  try {
5415
- const stat = Deno.statSync(path);
5416
+ const stat4 = Deno.statSync(path);
5416
5417
  if (options && (options.isReadable || options.isDirectory || options.isFile)) {
5417
5418
  if (options.isDirectory && options.isFile) {
5418
5419
  throw new TypeError("ExistsOptions.options.isDirectory and ExistsOptions.options.isFile must not be true together");
5419
5420
  }
5420
- if (options.isDirectory && !stat.isDirectory || options.isFile && !stat.isFile) {
5421
+ if (options.isDirectory && !stat4.isDirectory || options.isFile && !stat4.isFile) {
5421
5422
  return false;
5422
5423
  }
5423
5424
  if (options.isReadable) {
5424
- return fileIsReadable(stat);
5425
+ return fileIsReadable(stat4);
5425
5426
  }
5426
5427
  }
5427
5428
  return true;
@@ -5440,15 +5441,15 @@ function existsSync(path, options) {
5440
5441
  throw error;
5441
5442
  }
5442
5443
  }
5443
- function fileIsReadable(stat) {
5444
- if (stat.mode === null) {
5444
+ function fileIsReadable(stat4) {
5445
+ if (stat4.mode === null) {
5445
5446
  return true;
5446
- } else if (Deno.uid() === stat.uid) {
5447
- return (stat.mode & 256) === 256;
5448
- } else if (Deno.gid() === stat.gid) {
5449
- return (stat.mode & 32) === 32;
5447
+ } else if (Deno.uid() === stat4.uid) {
5448
+ return (stat4.mode & 256) === 256;
5449
+ } else if (Deno.gid() === stat4.gid) {
5450
+ return (stat4.mode & 32) === 32;
5450
5451
  }
5451
- return (stat.mode & 4) === 4;
5452
+ return (stat4.mode & 4) === 4;
5452
5453
  }
5453
5454
 
5454
5455
  // node_modules/@jsr/david__dax/src/commands/test.js
@@ -9460,13 +9461,20 @@ function createPath(path) {
9460
9461
  }
9461
9462
  }
9462
9463
 
9464
+ // node_modules/@yao/jsr2npm/converter.js
9465
+ import { chmod, mkdir as mkdir2, readFile as readFile3, rename, rm, stat as stat3, writeFile as writeFile2 } from "node:fs/promises";
9466
+ import { join as join6 } from "node:path";
9467
+ import { mkdirSync } from "node:fs";
9468
+
9463
9469
  // node_modules/@yao/jsr2npm/bundler.js
9470
+ import { copyFile as copyFile2, mkdir, readdir, stat } from "node:fs/promises";
9471
+ import { join as join4 } from "node:path";
9464
9472
  async function bundleWithEsbuild(packageDir, inputFile, outputFile, externalPackages = []) {
9465
9473
  const { build } = await import("esbuild");
9466
- const entryPath = `${Deno.cwd()}/${packageDir}/${inputFile}`;
9467
- const outputPath = `${Deno.cwd()}/${packageDir}/dist/${outputFile}`;
9474
+ const entryPath = join4(process.cwd(), packageDir, inputFile);
9475
+ const outputPath = join4(process.cwd(), packageDir, "dist", outputFile);
9468
9476
  const outputDir = outputPath.split("/").slice(0, -1).join("/");
9469
- await Deno.mkdir(outputDir, {
9477
+ await mkdir(outputDir, {
9470
9478
  recursive: true
9471
9479
  });
9472
9480
  const externalList = externalPackages.length > 0 ? externalPackages.join(", ") : "none";
@@ -9491,19 +9499,22 @@ const require = createRequire(import.meta.url);`
9491
9499
  }
9492
9500
  async function copyTypeDeclarations(packageDir) {
9493
9501
  console.log("\n\u{1F4DD} Copying TypeScript declarations...");
9494
- const sourceDir = `${packageDir}/_dist`;
9495
- const targetDir = `${packageDir}/dist/types`;
9502
+ const sourceDir = join4(packageDir, "_dist");
9503
+ const targetDir = join4(packageDir, "dist", "types");
9496
9504
  try {
9497
- await Deno.stat(sourceDir);
9498
- await Deno.mkdir(targetDir, {
9505
+ await stat(sourceDir);
9506
+ await mkdir(targetDir, {
9499
9507
  recursive: true
9500
9508
  });
9501
- for await (const entry of Deno.readDir(sourceDir)) {
9502
- const source = `${sourceDir}/${entry.name}`;
9503
- const target = `${targetDir}/${entry.name}`;
9504
- if (entry.isFile) {
9505
- await Deno.copyFile(source, target);
9506
- } else if (entry.isDirectory) {
9509
+ const entries = await readdir(sourceDir, {
9510
+ withFileTypes: true
9511
+ });
9512
+ for (const entry of entries) {
9513
+ const source = join4(sourceDir, entry.name);
9514
+ const target = join4(targetDir, entry.name);
9515
+ if (entry.isFile()) {
9516
+ await copyFile2(source, target);
9517
+ } else if (entry.isDirectory()) {
9507
9518
  await copyDirectory(source, target);
9508
9519
  }
9509
9520
  console.log(` \u2705 Copied ${entry.name}`);
@@ -9514,33 +9525,38 @@ async function copyTypeDeclarations(packageDir) {
9514
9525
  }
9515
9526
  }
9516
9527
  async function copyDirectory(source, target) {
9517
- await Deno.mkdir(target, {
9528
+ await mkdir(target, {
9518
9529
  recursive: true
9519
9530
  });
9520
- for await (const entry of Deno.readDir(source)) {
9521
- const sourcePath = `${source}/${entry.name}`;
9522
- const targetPath = `${target}/${entry.name}`;
9523
- if (entry.isFile) {
9524
- await Deno.copyFile(sourcePath, targetPath);
9525
- } else if (entry.isDirectory) {
9531
+ const entries = await readdir(source, {
9532
+ withFileTypes: true
9533
+ });
9534
+ for (const entry of entries) {
9535
+ const sourcePath = join4(source, entry.name);
9536
+ const targetPath = join4(target, entry.name);
9537
+ if (entry.isFile()) {
9538
+ await copyFile2(sourcePath, targetPath);
9539
+ } else if (entry.isDirectory()) {
9526
9540
  await copyDirectory(sourcePath, targetPath);
9527
9541
  }
9528
9542
  }
9529
9543
  }
9530
9544
 
9531
9545
  // node_modules/@yao/jsr2npm/package-generator.js
9546
+ import { copyFile as copyFile3, readFile as readFile2, stat as stat2, writeFile } from "node:fs/promises";
9547
+ import { join as join5 } from "node:path";
9532
9548
  async function generatePackageJson(packageDir, bin, overrides) {
9533
9549
  console.log("\n\u{1F4CB} Generating package.json...");
9534
9550
  const jsrPkg = await readPackageJson(`${packageDir}/package.json`);
9535
9551
  const denoJson = await readDenoJson(packageDir);
9536
9552
  const dependencies = getNpmDependencies(jsrPkg.dependencies);
9537
9553
  const newPkg = buildPackageJson(jsrPkg, denoJson, dependencies, bin, overrides);
9538
- await Deno.writeTextFile(`${packageDir}/dist/package.json`, JSON.stringify(newPkg, null, 2));
9554
+ await writeFile(join5(packageDir, "dist", "package.json"), JSON.stringify(newPkg, null, 2));
9539
9555
  console.log(`\u2705 Generated package.json with ${Object.keys(dependencies).length} dependencies`);
9540
9556
  }
9541
9557
  async function readPackageJson(path) {
9542
9558
  try {
9543
- const content = await Deno.readTextFile(path);
9559
+ const content = await readFile2(path, "utf-8");
9544
9560
  return JSON.parse(content);
9545
9561
  } catch {
9546
9562
  return {
@@ -9556,7 +9572,7 @@ async function readDenoJson(packageDir) {
9556
9572
  "deno.jsonc"
9557
9573
  ]) {
9558
9574
  try {
9559
- const content = await Deno.readTextFile(`${packageDir}/${file}`);
9575
+ const content = await readFile2(join5(packageDir, file), "utf-8");
9560
9576
  console.log(`\u2705 Found ${file}`);
9561
9577
  return JSON.parse(content);
9562
9578
  } catch {
@@ -9706,8 +9722,8 @@ async function copyExtraFiles(sourceDir, targetDir) {
9706
9722
  ];
9707
9723
  for (const file of files) {
9708
9724
  try {
9709
- await Deno.stat(`${sourceDir}/${file}`);
9710
- await Deno.copyFile(`${sourceDir}/${file}`, `${targetDir}/${file}`);
9725
+ await stat2(join5(sourceDir, file));
9726
+ await copyFile3(join5(sourceDir, file), join5(targetDir, file));
9711
9727
  console.log(` \u2705 Copied ${file}`);
9712
9728
  } catch {
9713
9729
  }
@@ -9723,12 +9739,12 @@ async function convertPackage(packageName, version, bin, overrides) {
9723
9739
  console.log(`\u{1F527} CLI Commands: ${Object.keys(bin).join(", ")}`);
9724
9740
  }
9725
9741
  const workspaceDir = createWorkspace(packageName, version);
9726
- const originalCwd = Deno.cwd();
9742
+ const originalCwd = process.cwd();
9727
9743
  try {
9728
- Deno.chdir(workspaceDir);
9744
+ process.chdir(workspaceDir);
9729
9745
  await installJSRPackage(packageName, version);
9730
- const packageDir = `node_modules/${packageName}`;
9731
- await Deno.mkdir(`${packageDir}/dist`, {
9746
+ const packageDir = join6("node_modules", packageName);
9747
+ await mkdir2(join6(packageDir, "dist"), {
9732
9748
  recursive: true
9733
9749
  });
9734
9750
  const externalPackages = await getExternalPackages(packageDir);
@@ -9740,12 +9756,12 @@ async function convertPackage(packageName, version, bin, overrides) {
9740
9756
  console.log("\n\u2705 Conversion completed!");
9741
9757
  console.log(`\u{1F4C2} Output: ${workspaceDir}/dist`);
9742
9758
  } finally {
9743
- Deno.chdir(originalCwd);
9759
+ process.chdir(originalCwd);
9744
9760
  }
9745
9761
  }
9746
9762
  function createWorkspace(packageName, version) {
9747
9763
  const folderName = packageName.replace(/[@\/]/g, "__") + `_${version}`;
9748
- Deno.mkdirSync(folderName, {
9764
+ mkdirSync(folderName, {
9749
9765
  recursive: true
9750
9766
  });
9751
9767
  console.log(`\u{1F4C1} Created folder: ${folderName}`);
@@ -9753,7 +9769,7 @@ function createWorkspace(packageName, version) {
9753
9769
  }
9754
9770
  async function getExternalPackages(packageDir) {
9755
9771
  try {
9756
- const content = await Deno.readTextFile(`${packageDir}/package.json`);
9772
+ const content = await readFile3(join6(packageDir, "package.json"), "utf-8");
9757
9773
  const pkgJson = JSON.parse(content);
9758
9774
  if (!pkgJson.dependencies) return [];
9759
9775
  const topLevelDeps = {};
@@ -9781,8 +9797,8 @@ async function findConflictingPackages(packageDir, jsrPackages, topLevelDeps) {
9781
9797
  const conflicts = /* @__PURE__ */ new Set();
9782
9798
  for (const jsrPkg of jsrPackages) {
9783
9799
  try {
9784
- const jsrPkgPath = `${packageDir}/node_modules/${jsrPkg}/package.json`;
9785
- const jsrContent = await Deno.readTextFile(jsrPkgPath);
9800
+ const jsrPkgPath = join6(packageDir, "node_modules", jsrPkg, "package.json");
9801
+ const jsrContent = await readFile3(jsrPkgPath, "utf-8");
9786
9802
  const jsrPkgJson = JSON.parse(jsrContent);
9787
9803
  if (!jsrPkgJson.dependencies) continue;
9788
9804
  for (const [depName, depVersion] of Object.entries(jsrPkgJson.dependencies)) {
@@ -9815,8 +9831,8 @@ async function bundleBinCommands(packageDir, bin, externalPackages) {
9815
9831
  await verifyEntrypoint(packageDir, inputFile);
9816
9832
  const outputFile = `bin/${cmdName}.mjs`;
9817
9833
  await bundleWithEsbuild(packageDir, inputFile, outputFile, externalPackages);
9818
- const outputPath = `${packageDir}/dist/${outputFile}`;
9819
- await Deno.chmod(outputPath, 493);
9834
+ const outputPath = join6(packageDir, "dist", outputFile);
9835
+ await chmod(outputPath, 493);
9820
9836
  console.log(` \u2705 Created ${cmdName}: ${outputFile}`);
9821
9837
  }
9822
9838
  }
@@ -9832,14 +9848,14 @@ async function bundleLibraryExports(packageDir, externalPackages) {
9832
9848
  }
9833
9849
  }
9834
9850
  async function installJSRPackage(packageName, version) {
9835
- await Deno.writeTextFile("package.json", "{}");
9851
+ await writeFile2("package.json", "{}");
9836
9852
  const packageSpec = version === "latest" ? packageName : `${packageName}@${version}`;
9837
9853
  console.log(`\u{1F504} Installing: ${packageSpec}`);
9838
- await mod_default`npx jsr add ${packageSpec}`.cwd(Deno.cwd());
9854
+ await mod_default`npx jsr add ${packageSpec}`.cwd(process.cwd());
9839
9855
  }
9840
9856
  async function verifyEntrypoint(packageDir, entrypoint) {
9841
9857
  try {
9842
- await Deno.stat(`${packageDir}/${entrypoint}`);
9858
+ await stat3(join6(packageDir, entrypoint));
9843
9859
  console.log(`\u2705 Found ${entrypoint}`);
9844
9860
  } catch {
9845
9861
  throw new Error(`\u274C ${entrypoint} not found in ${packageDir}`);
@@ -9851,7 +9867,7 @@ async function readDenoJsonExports(packageDir) {
9851
9867
  "deno.jsonc"
9852
9868
  ]) {
9853
9869
  try {
9854
- const content = await Deno.readTextFile(`${packageDir}/${file}`);
9870
+ const content = await readFile3(join6(packageDir, file), "utf-8");
9855
9871
  const denoJson = JSON.parse(content);
9856
9872
  if (!denoJson.exports) continue;
9857
9873
  const exports = {};
@@ -9869,22 +9885,22 @@ async function readDenoJsonExports(packageDir) {
9869
9885
  return null;
9870
9886
  }
9871
9887
  async function moveDistToRoot(packageDir) {
9872
- const sourceDist = `${packageDir}/dist`;
9873
- const targetDist = `${Deno.cwd()}/dist`;
9888
+ const sourceDist = join6(packageDir, "dist");
9889
+ const targetDist = join6(process.cwd(), "dist");
9874
9890
  try {
9875
- await Deno.remove(targetDist, {
9891
+ await rm(targetDist, {
9876
9892
  recursive: true
9877
9893
  });
9878
9894
  } catch {
9879
9895
  }
9880
- await Deno.rename(sourceDist, targetDist);
9896
+ await rename(sourceDist, targetDist);
9881
9897
  await copyExtraFiles(packageDir, targetDist);
9882
9898
  }
9883
9899
 
9884
9900
  // node_modules/@yao/jsr2npm/cli.ts
9885
9901
  async function main() {
9886
9902
  console.log("\u{1F680} JSR to NPM Package Converter\n");
9887
- const configFile = Deno.args[0] || "jsr2npm.config.json";
9903
+ const configFile = process.argv[2] || "jsr2npm.config.json";
9888
9904
  const config = await loadConfig(configFile);
9889
9905
  if (!config?.packages?.length) {
9890
9906
  console.error("\u274C No packages found in jsr2npm.config.json");
@@ -9906,7 +9922,7 @@ async function main() {
9906
9922
  ]
9907
9923
  }
9908
9924
  `);
9909
- Deno.exit(1);
9925
+ process.exit(1);
9910
9926
  }
9911
9927
  console.log(`\u{1F4CB} Found ${config.packages.length} package(s) in config
9912
9928
  `);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yaonyan/jsr2npm",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "homepage": "https://jsr.io/@yao/jsr2npm",
5
5
  "type": "module",
6
6
  "dependencies": {