Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"license": "MIT",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"type": "module",
"homepage": "https://next2d.app",
"bugs": "https://github.com/Next2D/create-next2d-app/issues",
"keywords": [
Expand All @@ -27,7 +28,6 @@
"create-next2d-app": "dist/index.js"
},
"dependencies": {
"@types/node": "^25.5.0",
"commander": "14.0.3",
"cross-spawn": "7.0.6",
"fs-extra": "11.3.4",
Expand All @@ -36,8 +36,13 @@
"validate-npm-package-name": "7.0.2"
},
"devDependencies": {
"@types/node": "^25.5.0",
"@eslint/eslintrc": "^3.3.5",
"@eslint/js": "^10.0.1",
"@types/cross-spawn": "^6.0.6",
"@types/fs-extra": "^11.0.4",
"@types/semver": "^7.7.1",
"@types/validate-npm-package-name": "^4.0.2",
"@typescript-eslint/eslint-plugin": "^8.58.0",
"@typescript-eslint/parser": "^8.58.0",
"eslint": "^10.1.0",
Expand Down
34 changes: 18 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

"use strict";

const pc = require("picocolors");
const commander = require("commander");
const packageJson = require("../package.json");
const path = require("path");
const validateProjectName = require("validate-npm-package-name");
const execSync = require("child_process").execSync;
const fs = require("fs-extra");
const os = require("os");
const semver = require("semver");
const spawn = require("cross-spawn");
import pc from "picocolors";
import { Command } from "commander";
import packageJson from "../package.json" with { type: "json" };
import path from "path";
import validateProjectName from "validate-npm-package-name";
import { execSync } from "child_process";
import { createRequire } from "module";
import fs from "fs-extra";
import os from "os";
import semver from "semver";
import spawn from "cross-spawn";

const recommendedVersion: number = 22;
const version: string = process.versions.node;
Expand Down Expand Up @@ -87,7 +88,7 @@ const checkThatNpmCanReadCwd = (): boolean =>
let childOutput: string = "";
try {
childOutput = spawn.sync("npm", ["config", "list"]).output.join("");
} catch (err) {
} catch {
return true;
}

Expand Down Expand Up @@ -155,7 +156,7 @@ const checkNpmVersion = (): NpmVersion =>
try {
npmVersion = execSync("npm --version").toString().trim();
hasMinNpm = semver.gte(npmVersion, "10.0.0");
} catch (err) {
} catch {
// ignore
}

Expand Down Expand Up @@ -222,19 +223,20 @@ const install = (
console.log();
console.log(`Installing template: ${pc.green(template)}`);

const requireFromRoot = createRequire(`${root}/package.json`);

Copilot AI Apr 2, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createRequire is being called with a path built via string concatenation (${root}/package.json). Since root comes from path.resolve() and may contain platform-specific separators (notably on Windows), using path.join(root, "package.json") (or a file URL via pathToFileURL) would make this more robust and consistent with the other path handling in this function.

Suggested change
const requireFromRoot = createRequire(`${root}/package.json`);
const requireFromRoot = createRequire(path.join(root, "package.json"));

Copilot uses AI. Check for mistakes.
const templatePath: string = path.dirname(
require.resolve(`${template}/package.json`, { "paths": [root] })
requireFromRoot.resolve(`${template}/package.json`)
);

const templateJsonPath: string = path.join(templatePath, "template.json");

let templateJson: TemplateJson = {};
if (fs.existsSync(templateJsonPath)) {
templateJson = require(templateJsonPath);
templateJson = JSON.parse(fs.readFileSync(templateJsonPath, "utf8")) as TemplateJson;
}

// base package.json
const packageJson = require(`${root}/package.json`);
const packageJson = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));

// reset
packageJson.dependencies = {};
Expand Down Expand Up @@ -516,7 +518,7 @@ const createApp = (
*/
const execute = (): void =>
{
const program = new commander.Command(packageJson.name)
const program = new Command(packageJson.name)
.version(packageJson.version)
.arguments("<project-directory>")
.usage(`${pc.green("<project-directory>")} [options]`)
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

"declaration": true,
"rootDir": "./src",
"outDir": "./dist"
"outDir": "./dist",
"types": ["node"]
},
"include": [
"src/index.ts"
Expand Down
Loading