From c620d3a28182f878977245eefa4f9313e9844acf Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sat, 28 Oct 2023 12:55:20 +0900 Subject: [PATCH] fix: migrate `create-app` and `create-theme` to ESM, close #1166 --- packages/create-app/{index.js => index.mjs} | 23 +++++++++++-------- packages/create-app/package.json | 5 ++-- packages/create-theme/{index.js => index.mjs} | 21 ++++++++++------- packages/create-theme/package.json | 5 ++-- tsconfig.json | 2 +- 5 files changed, 34 insertions(+), 22 deletions(-) rename packages/create-app/{index.js => index.mjs} (90%) rename packages/create-theme/{index.js => index.mjs} (89%) diff --git a/packages/create-app/index.js b/packages/create-app/index.mjs similarity index 90% rename from packages/create-app/index.js rename to packages/create-app/index.mjs index e3762c41b0..d0bee7fad3 100644 --- a/packages/create-app/index.js +++ b/packages/create-app/index.mjs @@ -2,16 +2,21 @@ /* eslint-disable no-console */ // @ts-check -const process = require('node:process') -const fs = require('node:fs') -const path = require('node:path') -const argv = require('minimist')(process.argv.slice(2)) -const prompts = require('prompts') -const execa = require('execa') -const { cyan, blue, yellow, bold, dim, green } = require('kolorist') -const { version } = require('./package.json') - +import process from 'node:process' +import fs from 'node:fs' +import path from 'node:path' +import { createRequire } from 'node:module' +import { fileURLToPath } from 'node:url' +import minimist from 'minimist' +import prompts from 'prompts' +import { execa } from 'execa' +import { blue, bold, cyan, dim, green, yellow } from 'kolorist' + +const argv = minimist(process.argv.slice(2)) const cwd = process.cwd() +const require = createRequire(import.meta.url) +const __dirname = fileURLToPath(new URL('.', import.meta.url)) +const { version } = require('./package.json') const renameFiles = { _gitignore: '.gitignore', diff --git a/packages/create-app/package.json b/packages/create-app/package.json index bda681e6c4..60575e5013 100644 --- a/packages/create-app/package.json +++ b/packages/create-app/package.json @@ -1,5 +1,6 @@ { "name": "create-slidev", + "type": "module", "version": "0.43.11", "description": "Create starter template for Slidev", "author": "antfu ", @@ -11,9 +12,9 @@ "url": "https://github.com/slidevjs/slidev" }, "bugs": "https://github.com/slidevjs/slidev/issues", - "main": "index.js", + "main": "index.mjs", "bin": { - "create-slidev": "index.js" + "create-slidev": "index.mjs" }, "engines": { "node": ">=18.0.0" diff --git a/packages/create-theme/index.js b/packages/create-theme/index.mjs similarity index 89% rename from packages/create-theme/index.js rename to packages/create-theme/index.mjs index 29b46fd3e6..85f15580fe 100644 --- a/packages/create-theme/index.js +++ b/packages/create-theme/index.mjs @@ -2,15 +2,20 @@ /* eslint-disable no-console */ // @ts-check -const process = require('node:process') -const fs = require('node:fs') -const path = require('node:path') -const argv = require('minimist')(process.argv.slice(2)) -const prompts = require('prompts') -const { cyan, blue, yellow, bold, dim, green } = require('kolorist') -const { version } = require('./package.json') - +import process from 'node:process' +import fs from 'node:fs' +import path from 'node:path' +import { createRequire } from 'node:module' +import { fileURLToPath } from 'node:url' +import minimist from 'minimist' +import prompts from 'prompts' +import { blue, bold, cyan, dim, green, yellow } from 'kolorist' + +const argv = minimist(process.argv.slice(2)) const cwd = process.cwd() +const require = createRequire(import.meta.url) +const __dirname = fileURLToPath(new URL('.', import.meta.url)) +const { version } = require('./package.json') const renameFiles = { _gitignore: '.gitignore', diff --git a/packages/create-theme/package.json b/packages/create-theme/package.json index ca8d8a30f7..1c4fb5b11c 100644 --- a/packages/create-theme/package.json +++ b/packages/create-theme/package.json @@ -1,5 +1,6 @@ { "name": "create-slidev-theme", + "type": "module", "version": "0.43.11", "description": "Create starter theme template for Slidev", "author": "antfu ", @@ -11,9 +12,9 @@ "url": "https://github.com/slidevjs/slidev" }, "bugs": "https://github.com/slidevjs/slidev/issues", - "main": "index.js", + "main": "index.mjs", "bin": { - "create-slidev-theme": "index.js" + "create-slidev-theme": "index.mjs" }, "engines": { "node": ">=18.0.0" diff --git a/tsconfig.json b/tsconfig.json index fc528fe0d1..e38320fd89 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "target": "es2020", + "target": "es2022", "jsx": "preserve", "lib": ["DOM", "ESNext"], "baseUrl": ".",