From 5b2c92bad93e2627c21761ff9a9ada10fc54ef16 Mon Sep 17 00:00:00 2001 From: ienaga Date: Thu, 2 Apr 2026 23:03:20 +0900 Subject: [PATCH 1/2] =?UTF-8?q?#65=20index.ts=E3=81=AE=E8=A8=98=E8=BF=B0?= =?UTF-8?q?=E3=82=92TypeScript=20v6=E3=81=AB=E5=90=88=E3=82=8F=E3=81=9B?= =?UTF-8?q?=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 53 ++++++++++++++++++++++++++++++++++++++++++++++- package.json | 6 +++++- src/index.ts | 34 ++++++++++++++++-------------- tsconfig.json | 3 ++- 4 files changed, 77 insertions(+), 19 deletions(-) diff --git a/package-lock.json b/package-lock.json index c766ead..5795111 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,6 @@ "version": "2.2.2", "license": "MIT", "dependencies": { - "@types/node": "^25.5.0", "commander": "14.0.3", "cross-spawn": "7.0.6", "fs-extra": "11.3.4", @@ -23,6 +22,11 @@ "devDependencies": { "@eslint/eslintrc": "^3.3.5", "@eslint/js": "^10.0.1", + "@types/cross-spawn": "^6.0.6", + "@types/fs-extra": "^11.0.4", + "@types/node": "^25.5.0", + "@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", @@ -274,6 +278,16 @@ "url": "https://github.com/sponsors/nzakas" } }, + "node_modules/@types/cross-spawn": { + "version": "6.0.6", + "resolved": "https://registry.npmjs.org/@types/cross-spawn/-/cross-spawn-6.0.6.tgz", + "integrity": "sha512-fXRhhUkG4H3TQk5dBhQ7m/JDdSNHKwR2BBia62lhwEIq9xGiQKLxd6LymNhn47SjXhsUEPmxi+PKw2OkW4LLjA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/esrecurse": { "version": "4.3.1", "resolved": "https://registry.npmjs.org/@types/esrecurse/-/esrecurse-4.3.1.tgz", @@ -288,6 +302,17 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/fs-extra": { + "version": "11.0.4", + "resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-11.0.4.tgz", + "integrity": "sha512-yTbItCNreRooED33qjunPthRcSjERP1r4MqCZc7wv0u2sUkzTFp45tgUfS5+r7FrZPdmCCNflLhVSP/o+SemsQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/jsonfile": "*", + "@types/node": "*" + } + }, "node_modules/@types/json-schema": { "version": "7.0.15", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", @@ -295,15 +320,40 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/jsonfile": { + "version": "6.1.4", + "resolved": "https://registry.npmjs.org/@types/jsonfile/-/jsonfile-6.1.4.tgz", + "integrity": "sha512-D5qGUYwjvnNNextdU59/+fI+spnwtTFmyQP0h+PfIOSkNfpU6AOICUOkm4i0OnSk+NyjdPJrxCDro0sJsWlRpQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/node": { "version": "25.5.0", "resolved": "https://registry.npmjs.org/@types/node/-/node-25.5.0.tgz", "integrity": "sha512-jp2P3tQMSxWugkCUKLRPVUpGaL5MVFwF8RDuSRztfwgN1wmqJeMSbKlnEtQqU8UrhTmzEmZdu2I6v2dpp7XIxw==", + "dev": true, "license": "MIT", "dependencies": { "undici-types": "~7.18.0" } }, + "node_modules/@types/semver": { + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.7.1.tgz", + "integrity": "sha512-FmgJfu+MOcQ370SD0ev7EI8TlCAfKYU+B4m5T3yXc1CiRN94g/SZPtsCkk506aUDtlMnFZvasDwHHUcZUEaYuA==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/validate-npm-package-name": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/@types/validate-npm-package-name/-/validate-npm-package-name-4.0.2.tgz", + "integrity": "sha512-lrpDziQipxCEeK5kWxvljWYhUvOiB2A9izZd9B2AFarYAkqZshb4lPbRs7zKEic6eGtH8V/2qJW+dPp9OtF6bw==", + "dev": true, + "license": "MIT" + }, "node_modules/@typescript-eslint/eslint-plugin": { "version": "8.58.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.58.0.tgz", @@ -1533,6 +1583,7 @@ "version": "7.18.2", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.18.2.tgz", "integrity": "sha512-AsuCzffGHJybSaRrmr5eHr81mwJU3kjw6M+uprWvCXiNeN9SOGwQ3Jn8jb8m3Z6izVgknn1R0FTCEAP2QrLY/w==", + "dev": true, "license": "MIT" }, "node_modules/universalify": { diff --git a/package.json b/package.json index ef3cc67..99209a0 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,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", @@ -36,8 +35,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", diff --git a/src/index.ts b/src/index.ts index eac3994..f3d8234 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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"; +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; @@ -87,7 +88,7 @@ const checkThatNpmCanReadCwd = (): boolean => let childOutput: string = ""; try { childOutput = spawn.sync("npm", ["config", "list"]).output.join(""); - } catch (err) { + } catch { return true; } @@ -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 } @@ -222,19 +223,20 @@ const install = ( console.log(); console.log(`Installing template: ${pc.green(template)}`); + const requireFromRoot = createRequire(`${root}/package.json`); 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 = {}; @@ -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("") .usage(`${pc.green("")} [options]`) diff --git a/tsconfig.json b/tsconfig.json index cec73cd..5f1f4ce 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -19,7 +19,8 @@ "declaration": true, "rootDir": "./src", - "outDir": "./dist" + "outDir": "./dist", + "types": ["node"] }, "include": [ "src/index.ts" From 6e155c7c9d46ae6c43bbf2eb4b90740219f9cfc6 Mon Sep 17 00:00:00 2001 From: ienaga Date: Fri, 3 Apr 2026 00:25:38 +0900 Subject: [PATCH 2/2] =?UTF-8?q?#65=20TypeScript=20v6=E3=81=B8=E5=AF=BE?= =?UTF-8?q?=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + src/index.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 99209a0..bcf8a6f 100644 --- a/package.json +++ b/package.json @@ -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": [ diff --git a/src/index.ts b/src/index.ts index f3d8234..def71d1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,7 +4,7 @@ import pc from "picocolors"; import { Command } from "commander"; -import packageJson from "../package.json"; +import packageJson from "../package.json" with { type: "json" }; import path from "path"; import validateProjectName from "validate-npm-package-name"; import { execSync } from "child_process";