Skip to content

Commit 2aeb941

Browse files
committed
feat: use type=module in generated projects
For Cypress with Typescript, we needed to add a `module` option to the root tsconfig (see cypress-io/cypress#24111).
1 parent e69de26 commit 2aeb941

File tree

14 files changed

+25
-52
lines changed

14 files changed

+25
-52
lines changed

index.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -447,17 +447,20 @@ async function init() {
447447

448448
if (needsTypeScript) {
449449
// Convert the JavaScript template to the TypeScript
450-
// Check all the remaining `.js` files:
451-
// - If the corresponding TypeScript version already exists, remove the `.js` version.
452-
// - Otherwise, rename the `.js` file to `.ts`
450+
// Check all the remaining `.js`/`.cjs` files:
451+
// - If the corresponding TypeScript version already exists, remove the `.js`/`.cjs` version.
452+
// - Otherwise, rename the `.js`/`.cjs` file to `.ts`
453453
// Remove `jsconfig.json`, because we already have tsconfig.json
454454
// `jsconfig.json` is not reused, because we use solution-style `tsconfig`s, which are much more complicated.
455455
preOrderDirectoryTraverse(
456456
root,
457457
() => {},
458458
(filepath) => {
459-
if (filepath.endsWith('.js') && !FILES_TO_FILTER.includes(path.basename(filepath))) {
460-
const tsFilePath = filepath.replace(/\.js$/, '.ts')
459+
if (
460+
(filepath.endsWith('.js') || filepath.endsWith('.cjs')) &&
461+
!FILES_TO_FILTER.includes(path.basename(filepath))
462+
) {
463+
const tsFilePath = filepath.replace(/\.c?js$/, '.ts')
461464
if (fs.existsSync(tsFilePath)) {
462465
fs.unlinkSync(filepath)
463466
} else {

pnpm-lock.yaml

+5-39
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

template/base/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"private": true,
3+
"type": "module",
34
"scripts": {
45
"dev": "vite",
56
"build": "vite build",

template/config/nightwatch/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
},
55
"devDependencies": {
66
"nightwatch": "^3.3.2",
7-
"@nightwatch/vue": "0.4.5",
7+
"@nightwatch/vue": "^0.4.5",
88
"@vitejs/plugin-vue": "^4.5.0",
99
"@types/nightwatch": "^2.3.28",
1010
"geckodriver": "^4.2.1",
1111
"chromedriver": "^119.0.0",
12-
"ts-node": "^10.9.1"
12+
"ts-node": "^10.9.1",
13+
"vite-plugin-nightwatch": "^0.4.5"
1314
}
1415
}

template/config/playwright/e2e/vue.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { test, expect } = require('@playwright/test');
1+
import { test, expect } from '@playwright/test';
22

33
// See here how to get started:
44
// https://playwright.dev/docs/intro

template/tsconfig/cypress-ct/tsconfig.json

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"files": [],
3+
"compilerOptions": {
4+
"module": "es2015"
5+
},
36
"references": [
47
{
58
"path": "./tsconfig.node.json"

template/tsconfig/vitest/tsconfig.json

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"files": [],
3+
"compilerOptions": {
4+
"module": "es2015"
5+
},
36
"references": [
47
{
58
"path": "./tsconfig.node.json"

utils/filterList.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
export const FILES_TO_FILTER = [
2-
'nightwatch.e2e.conf.js',
3-
'nightwatch.component.conf.js',
4-
'globals.js'
5-
]
1+
export const FILES_TO_FILTER = []

0 commit comments

Comments
 (0)