@yaonyan/jsr2npm 0.1.6 → 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/bin/jsr2npm.mjs +30 -16
- package/package.json +2 -2
package/bin/jsr2npm.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
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
7
|
import { resolve } from "node:path";
|
|
8
8
|
import process2 from "node:process";
|
|
@@ -16,17 +16,17 @@ async function loadConfig(configPath) {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
// node_modules/@yao/jsr2npm/converter.js
|
|
19
|
+
// __yao__jsr2npm_latest/node_modules/@yao/jsr2npm/converter.js
|
|
20
20
|
import $ from "dax-sh";
|
|
21
21
|
import { chmod, mkdir as mkdir2, readFile as readFile3, rename, rm, stat as stat3, writeFile as writeFile2 } from "node:fs/promises";
|
|
22
22
|
import { join as join3 } from "node:path";
|
|
23
23
|
import { mkdirSync } from "node:fs";
|
|
24
24
|
|
|
25
|
-
// node_modules/@yao/jsr2npm/bundler.js
|
|
25
|
+
// __yao__jsr2npm_latest/node_modules/@yao/jsr2npm/bundler.js
|
|
26
26
|
import { copyFile, mkdir, readdir, stat } from "node:fs/promises";
|
|
27
27
|
import { join } from "node:path";
|
|
28
|
+
import { build } from "esbuild";
|
|
28
29
|
async function bundleWithEsbuild(packageDir, inputFile, outputFile, externalPackages = []) {
|
|
29
|
-
const { build } = await import("esbuild");
|
|
30
30
|
const entryPath = join(process.cwd(), packageDir, inputFile);
|
|
31
31
|
const outputPath = join(process.cwd(), packageDir, "dist", outputFile);
|
|
32
32
|
const outputDir = outputPath.split("/").slice(0, -1).join("/");
|
|
@@ -98,14 +98,14 @@ async function copyDirectory(source, target) {
|
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
// node_modules/@yao/jsr2npm/package-generator.js
|
|
101
|
+
// __yao__jsr2npm_latest/node_modules/@yao/jsr2npm/package-generator.js
|
|
102
102
|
import { copyFile as copyFile2, readFile as readFile2, stat as stat2, writeFile } from "node:fs/promises";
|
|
103
103
|
import { join as join2 } from "node:path";
|
|
104
|
-
async function generatePackageJson(packageDir, bin, overrides) {
|
|
104
|
+
async function generatePackageJson(packageDir, bin, overrides, allDependencies) {
|
|
105
105
|
console.log("\n\u{1F4CB} Generating package.json...");
|
|
106
106
|
const jsrPkg = await readPackageJson(`${packageDir}/package.json`);
|
|
107
107
|
const denoJson = await readDenoJson(packageDir);
|
|
108
|
-
const dependencies = getNpmDependencies(jsrPkg.dependencies);
|
|
108
|
+
const dependencies = allDependencies || getNpmDependencies(jsrPkg.dependencies);
|
|
109
109
|
const newPkg = buildPackageJson(jsrPkg, denoJson, dependencies, bin, overrides);
|
|
110
110
|
await writeFile(join2(packageDir, "dist", "package.json"), JSON.stringify(newPkg, null, 2));
|
|
111
111
|
console.log(`\u2705 Generated package.json with ${Object.keys(dependencies).length} dependencies`);
|
|
@@ -286,7 +286,7 @@ async function copyExtraFiles(sourceDir, targetDir) {
|
|
|
286
286
|
}
|
|
287
287
|
}
|
|
288
288
|
|
|
289
|
-
// node_modules/@yao/jsr2npm/converter.js
|
|
289
|
+
// __yao__jsr2npm_latest/node_modules/@yao/jsr2npm/converter.js
|
|
290
290
|
async function convertPackage(packageName, version, bin, overrides) {
|
|
291
291
|
console.log(`
|
|
292
292
|
\u{1F4E6} Package: ${packageName}`);
|
|
@@ -303,11 +303,11 @@ async function convertPackage(packageName, version, bin, overrides) {
|
|
|
303
303
|
await mkdir2(join3(packageDir, "dist"), {
|
|
304
304
|
recursive: true
|
|
305
305
|
});
|
|
306
|
-
const
|
|
307
|
-
await bundlePackage(packageDir, bin,
|
|
306
|
+
const { externals, allDependencies } = await getExternalPackages(packageDir);
|
|
307
|
+
await bundlePackage(packageDir, bin, externals);
|
|
308
308
|
await copyTypeDeclarations(packageDir);
|
|
309
309
|
await copyExtraFiles(packageDir, `${packageDir}/dist`);
|
|
310
|
-
await generatePackageJson(packageDir, bin, overrides);
|
|
310
|
+
await generatePackageJson(packageDir, bin, overrides, allDependencies);
|
|
311
311
|
await moveDistToRoot(packageDir);
|
|
312
312
|
console.log("\n\u2705 Conversion completed!");
|
|
313
313
|
console.log(`\u{1F4C2} Output: ${workspaceDir}/dist`);
|
|
@@ -327,7 +327,10 @@ async function getExternalPackages(packageDir) {
|
|
|
327
327
|
try {
|
|
328
328
|
const content = await readFile3(join3(packageDir, "package.json"), "utf-8");
|
|
329
329
|
const pkgJson = JSON.parse(content);
|
|
330
|
-
if (!pkgJson.dependencies) return
|
|
330
|
+
if (!pkgJson.dependencies) return {
|
|
331
|
+
externals: [],
|
|
332
|
+
allDependencies: {}
|
|
333
|
+
};
|
|
331
334
|
const topLevelDeps = {};
|
|
332
335
|
for (const [name, version] of Object.entries(pkgJson.dependencies)) {
|
|
333
336
|
if (!name.startsWith("@jsr/")) {
|
|
@@ -344,16 +347,25 @@ async function getExternalPackages(packageDir) {
|
|
|
344
347
|
const conflictList = Array.from(conflictingPackages).join(", ");
|
|
345
348
|
console.log(`\u26A0\uFE0F Version conflicts, will bundle: ${conflictList}`);
|
|
346
349
|
}
|
|
347
|
-
return
|
|
350
|
+
return {
|
|
351
|
+
externals,
|
|
352
|
+
allDependencies: topLevelDeps
|
|
353
|
+
};
|
|
348
354
|
} catch {
|
|
349
|
-
return
|
|
355
|
+
return {
|
|
356
|
+
externals: [],
|
|
357
|
+
allDependencies: {}
|
|
358
|
+
};
|
|
350
359
|
}
|
|
351
360
|
}
|
|
352
361
|
async function findConflictingPackages(packageDir, jsrPackages, topLevelDeps) {
|
|
353
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("/");
|
|
354
366
|
for (const jsrPkg of jsrPackages) {
|
|
355
367
|
try {
|
|
356
|
-
const jsrPkgPath = join3(
|
|
368
|
+
const jsrPkgPath = join3(rootNodeModules, jsrPkg, "package.json");
|
|
357
369
|
const jsrContent = await readFile3(jsrPkgPath, "utf-8");
|
|
358
370
|
const jsrPkgJson = JSON.parse(jsrContent);
|
|
359
371
|
if (!jsrPkgJson.dependencies) continue;
|
|
@@ -366,6 +378,8 @@ async function findConflictingPackages(packageDir, jsrPackages, topLevelDeps) {
|
|
|
366
378
|
console.log(` Top-level: ${topLevelDeps[depName]}`);
|
|
367
379
|
console.log(` ${jsrPkg}: ${depVersion}`);
|
|
368
380
|
}
|
|
381
|
+
} else {
|
|
382
|
+
topLevelDeps[depName] = String(depVersion);
|
|
369
383
|
}
|
|
370
384
|
}
|
|
371
385
|
} catch {
|
|
@@ -453,7 +467,7 @@ async function moveDistToRoot(packageDir) {
|
|
|
453
467
|
await copyExtraFiles(packageDir, targetDist);
|
|
454
468
|
}
|
|
455
469
|
|
|
456
|
-
// node_modules/@yao/jsr2npm/cli.ts
|
|
470
|
+
// __yao__jsr2npm_latest/node_modules/@yao/jsr2npm/cli.ts
|
|
457
471
|
async function main() {
|
|
458
472
|
console.log("\u{1F680} JSR to NPM Package Converter\n");
|
|
459
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.
|
|
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.
|
|
8
|
+
"esbuild": "^0.25.10"
|
|
9
9
|
},
|
|
10
10
|
"exports": {
|
|
11
11
|
"./bin/jsr2npm": "./bin/jsr2npm.mjs",
|