@yaonyan/jsr2npm 0.1.5 → 0.1.7

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
@@ -97,9 +97,9 @@ structure and metadata.
97
97
  deno run --allow-all cli.ts
98
98
  ```
99
99
 
100
- Or use the remote version:
100
+ Or use npx:
101
101
  ```bash
102
- deno run --allow-all https://raw.githubusercontent.com/yaonyan/jsr2npm/main/cli.ts
102
+ npx -y @yaonyan/jsr2npm@latest
103
103
  ```
104
104
 
105
105
  ## How It Works
@@ -163,10 +163,10 @@ Run the conversion locally:
163
163
  deno run -A cli.ts
164
164
  ```
165
165
 
166
- Or use the remote version:
166
+ Or use npx to run the latest version:
167
167
 
168
168
  ```bash
169
- deno run -A https://raw.githubusercontent.com/yaonyan/jsr2npm/main/cli.ts
169
+ npx -y @yaonyan/jsr2npm@latest
170
170
  ```
171
171
 
172
172
  The converted packages will be in `__<scope>__<package>_<version>/dist/`
@@ -258,11 +258,11 @@ jobs:
258
258
  - name: Setup Node.js
259
259
  uses: actions/setup-node@v4
260
260
  with:
261
- node-version: "20"
261
+ node-version: "latest"
262
262
  registry-url: "https://registry.npmjs.org"
263
263
 
264
264
  - name: Run JSR to NPM conversion
265
- run: deno run -A https://raw.githubusercontent.com/yaonyan/jsr2npm/main/cli.ts
265
+ run: npx -y @yaonyan/jsr2npm@latest
266
266
 
267
267
  - name: Publish to npm
268
268
  run: |
package/bin/jsr2npm.mjs CHANGED
@@ -2,28 +2,31 @@
2
2
  import { createRequire } from 'node:module';
3
3
  const require = createRequire(import.meta.url);
4
4
 
5
- // node_modules/@yao/jsr2npm/config.js
5
+ // __yao__jsr2npm_latest/node_modules/@yao/jsr2npm/config.js
6
6
  import { readFile } from "node:fs/promises";
7
+ import { resolve } from "node:path";
8
+ import process2 from "node:process";
7
9
  async function loadConfig(configPath) {
8
10
  try {
9
- const content = await readFile(configPath, "utf-8");
11
+ const absolutePath = resolve(process2.cwd(), configPath);
12
+ const content = await readFile(absolutePath, "utf-8");
10
13
  return JSON.parse(content);
11
14
  } catch {
12
15
  return null;
13
16
  }
14
17
  }
15
18
 
16
- // node_modules/@yao/jsr2npm/converter.js
19
+ // __yao__jsr2npm_latest/node_modules/@yao/jsr2npm/converter.js
17
20
  import $ from "dax-sh";
18
21
  import { chmod, mkdir as mkdir2, readFile as readFile3, rename, rm, stat as stat3, writeFile as writeFile2 } from "node:fs/promises";
19
22
  import { join as join3 } from "node:path";
20
23
  import { mkdirSync } from "node:fs";
21
24
 
22
- // node_modules/@yao/jsr2npm/bundler.js
25
+ // __yao__jsr2npm_latest/node_modules/@yao/jsr2npm/bundler.js
23
26
  import { copyFile, mkdir, readdir, stat } from "node:fs/promises";
24
27
  import { join } from "node:path";
28
+ import { build } from "esbuild";
25
29
  async function bundleWithEsbuild(packageDir, inputFile, outputFile, externalPackages = []) {
26
- const { build } = await import("esbuild");
27
30
  const entryPath = join(process.cwd(), packageDir, inputFile);
28
31
  const outputPath = join(process.cwd(), packageDir, "dist", outputFile);
29
32
  const outputDir = outputPath.split("/").slice(0, -1).join("/");
@@ -95,14 +98,14 @@ async function copyDirectory(source, target) {
95
98
  }
96
99
  }
97
100
 
98
- // node_modules/@yao/jsr2npm/package-generator.js
101
+ // __yao__jsr2npm_latest/node_modules/@yao/jsr2npm/package-generator.js
99
102
  import { copyFile as copyFile2, readFile as readFile2, stat as stat2, writeFile } from "node:fs/promises";
100
103
  import { join as join2 } from "node:path";
101
- async function generatePackageJson(packageDir, bin, overrides) {
104
+ async function generatePackageJson(packageDir, bin, overrides, allDependencies) {
102
105
  console.log("\n\u{1F4CB} Generating package.json...");
103
106
  const jsrPkg = await readPackageJson(`${packageDir}/package.json`);
104
107
  const denoJson = await readDenoJson(packageDir);
105
- const dependencies = getNpmDependencies(jsrPkg.dependencies);
108
+ const dependencies = allDependencies || getNpmDependencies(jsrPkg.dependencies);
106
109
  const newPkg = buildPackageJson(jsrPkg, denoJson, dependencies, bin, overrides);
107
110
  await writeFile(join2(packageDir, "dist", "package.json"), JSON.stringify(newPkg, null, 2));
108
111
  console.log(`\u2705 Generated package.json with ${Object.keys(dependencies).length} dependencies`);
@@ -283,7 +286,7 @@ async function copyExtraFiles(sourceDir, targetDir) {
283
286
  }
284
287
  }
285
288
 
286
- // node_modules/@yao/jsr2npm/converter.js
289
+ // __yao__jsr2npm_latest/node_modules/@yao/jsr2npm/converter.js
287
290
  async function convertPackage(packageName, version, bin, overrides) {
288
291
  console.log(`
289
292
  \u{1F4E6} Package: ${packageName}`);
@@ -300,11 +303,11 @@ async function convertPackage(packageName, version, bin, overrides) {
300
303
  await mkdir2(join3(packageDir, "dist"), {
301
304
  recursive: true
302
305
  });
303
- const externalPackages = await getExternalPackages(packageDir);
304
- await bundlePackage(packageDir, bin, externalPackages);
306
+ const { externals, allDependencies } = await getExternalPackages(packageDir);
307
+ await bundlePackage(packageDir, bin, externals);
305
308
  await copyTypeDeclarations(packageDir);
306
309
  await copyExtraFiles(packageDir, `${packageDir}/dist`);
307
- await generatePackageJson(packageDir, bin, overrides);
310
+ await generatePackageJson(packageDir, bin, overrides, allDependencies);
308
311
  await moveDistToRoot(packageDir);
309
312
  console.log("\n\u2705 Conversion completed!");
310
313
  console.log(`\u{1F4C2} Output: ${workspaceDir}/dist`);
@@ -324,7 +327,10 @@ async function getExternalPackages(packageDir) {
324
327
  try {
325
328
  const content = await readFile3(join3(packageDir, "package.json"), "utf-8");
326
329
  const pkgJson = JSON.parse(content);
327
- if (!pkgJson.dependencies) return [];
330
+ if (!pkgJson.dependencies) return {
331
+ externals: [],
332
+ allDependencies: {}
333
+ };
328
334
  const topLevelDeps = {};
329
335
  for (const [name, version] of Object.entries(pkgJson.dependencies)) {
330
336
  if (!name.startsWith("@jsr/")) {
@@ -341,16 +347,25 @@ async function getExternalPackages(packageDir) {
341
347
  const conflictList = Array.from(conflictingPackages).join(", ");
342
348
  console.log(`\u26A0\uFE0F Version conflicts, will bundle: ${conflictList}`);
343
349
  }
344
- return externals;
350
+ return {
351
+ externals,
352
+ allDependencies: topLevelDeps
353
+ };
345
354
  } catch {
346
- return [];
355
+ return {
356
+ externals: [],
357
+ allDependencies: {}
358
+ };
347
359
  }
348
360
  }
349
361
  async function findConflictingPackages(packageDir, jsrPackages, topLevelDeps) {
350
362
  const conflicts = /* @__PURE__ */ new Set();
363
+ const parts = packageDir.split(/[\/\\]/);
364
+ const nodeModulesIndex = parts.indexOf("node_modules");
365
+ const rootNodeModules = parts.slice(0, nodeModulesIndex + 1).join("/");
351
366
  for (const jsrPkg of jsrPackages) {
352
367
  try {
353
- const jsrPkgPath = join3(packageDir, "node_modules", jsrPkg, "package.json");
368
+ const jsrPkgPath = join3(rootNodeModules, jsrPkg, "package.json");
354
369
  const jsrContent = await readFile3(jsrPkgPath, "utf-8");
355
370
  const jsrPkgJson = JSON.parse(jsrContent);
356
371
  if (!jsrPkgJson.dependencies) continue;
@@ -363,6 +378,8 @@ async function findConflictingPackages(packageDir, jsrPackages, topLevelDeps) {
363
378
  console.log(` Top-level: ${topLevelDeps[depName]}`);
364
379
  console.log(` ${jsrPkg}: ${depVersion}`);
365
380
  }
381
+ } else {
382
+ topLevelDeps[depName] = String(depVersion);
366
383
  }
367
384
  }
368
385
  } catch {
@@ -450,7 +467,7 @@ async function moveDistToRoot(packageDir) {
450
467
  await copyExtraFiles(packageDir, targetDist);
451
468
  }
452
469
 
453
- // node_modules/@yao/jsr2npm/cli.ts
470
+ // __yao__jsr2npm_latest/node_modules/@yao/jsr2npm/cli.ts
454
471
  async function main() {
455
472
  console.log("\u{1F680} JSR to NPM Package Converter\n");
456
473
  const configFile = process.argv[2] || "jsr2npm.config.json";
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@yaonyan/jsr2npm",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "homepage": "https://jsr.io/@yao/jsr2npm",
5
5
  "type": "module",
6
6
  "dependencies": {
7
7
  "dax-sh": "^0.43.2",
8
- "esbuild": "0.25.5"
8
+ "esbuild": "^0.25.10"
9
9
  },
10
10
  "exports": {
11
11
  "./bin/jsr2npm": "./bin/jsr2npm.mjs",