Skip to content

feat: use type=module in generated projects #389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
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
13 changes: 8 additions & 5 deletions index.ts
Original file line number Diff line number Diff line change
@@ -447,17 +447,20 @@ async function init() {

if (needsTypeScript) {
// Convert the JavaScript template to the TypeScript
// Check all the remaining `.js` files:
// - If the corresponding TypeScript version already exists, remove the `.js` version.
// - Otherwise, rename the `.js` file to `.ts`
// Check all the remaining `.js`/`.cjs` files:
// - If the corresponding TypeScript version already exists, remove the `.js`/`.cjs` version.
// - Otherwise, rename the `.js`/`.cjs` file to `.ts`
// Remove `jsconfig.json`, because we already have tsconfig.json
// `jsconfig.json` is not reused, because we use solution-style `tsconfig`s, which are much more complicated.
preOrderDirectoryTraverse(
root,
() => {},
(filepath) => {
if (filepath.endsWith('.js') && !FILES_TO_FILTER.includes(path.basename(filepath))) {
const tsFilePath = filepath.replace(/\.js$/, '.ts')
if (
(filepath.endsWith('.js') || filepath.endsWith('.cjs')) &&
!FILES_TO_FILTER.includes(path.basename(filepath))
) {
const tsFilePath = filepath.replace(/\.c?js$/, '.ts')
if (fs.existsSync(tsFilePath)) {
fs.unlinkSync(filepath)
} else {
53 changes: 10 additions & 43 deletions pnpm-lock.yaml

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

23 changes: 18 additions & 5 deletions scripts/test.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#!/usr/bin/env zx
import 'zx/globals'

// Vitest would otherwise enable watch mode by default.
process.env.CI = '1'

const playgroundDir = path.resolve(__dirname, '../playground/')
let projects = fs
.readdirSync(playgroundDir, { withFileTypes: true })
@@ -21,7 +18,13 @@ for (const projectName of projects) {
cd(path.resolve(playgroundDir, projectName))
const packageJSON = require(path.resolve(playgroundDir, projectName, 'package.json'))

console.log(`Building ${projectName}`)
console.log(`
#####
Building ${projectName}
#####
`)
await $`pnpm build`

if ('@playwright/test' in packageJSON.devDependencies) {
@@ -35,6 +38,16 @@ for (const projectName of projects) {

if ('test:unit' in packageJSON.scripts) {
console.log(`Running unit tests in ${projectName}`)
await $`pnpm test:unit`
if (projectName.includes('vitest') || projectName.includes('with-tests')) {
// Vitest would otherwise enable watch mode by default.
await $`CI=1 pnpm test:unit`
} else {
await $`pnpm test:unit`
}
}

if ('type-check' in packageJSON.scripts) {
console.log(`Running type-check in ${projectName}`)
await $`pnpm type-check`
}
}
3 changes: 2 additions & 1 deletion template/base/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
@@ -10,6 +11,6 @@
},
"devDependencies": {
"@vitejs/plugin-vue": "^4.5.0",
"vite": "^5.0.1"
"vite": "^5.0.2"
}
}
File renamed without changes.
5 changes: 4 additions & 1 deletion template/config/nightwatch-ct/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
"scripts": {
"test:unit": "nightwatch src/components/**/__tests__/*"
"test:unit": "nightwatch src/**/__tests__/*"
},
"dependencies": {
"vue": "^3.3.8"
},
"devDependencies": {
"@vue/test-utils": "^2.4.2"
}
}
Original file line number Diff line number Diff line change
@@ -30,10 +30,11 @@ module.exports = {
plugins: ['@nightwatch/vue'],

// See https://nightwatchjs.org/guide/concepts/test-globals.html#external-test-globals
globals_path: 'nightwatch/globals.js',
globals_path: '',

vite_dev_server: {
start_vite: false
start_vite: true,
port: process.env.CI ? 4173 : 5173
},

webdriver: {},
23 changes: 0 additions & 23 deletions template/config/nightwatch/nightwatch/globals.js

This file was deleted.

6 changes: 3 additions & 3 deletions template/config/nightwatch/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"scripts": {
"test:e2e": "nightwatch tests/e2e"
"test:e2e": "nightwatch tests/e2e/*"
},
"devDependencies": {
"nightwatch": "^3.3.2",
"@nightwatch/vue": "0.4.5",
"@nightwatch/vue": "^0.4.5",
"@vitejs/plugin-vue": "^4.5.0",
"@types/nightwatch": "^2.3.28",
"geckodriver": "^4.2.1",
"chromedriver": "^119.0.0",
"ts-node": "^10.9.1",
"wait-on": "^7.2.0"
"vite-plugin-nightwatch": "^0.4.5"
}
}
5 changes: 1 addition & 4 deletions template/config/nightwatch/tests/e2e/example.js
Original file line number Diff line number Diff line change
@@ -4,10 +4,7 @@ describe('My First Test', function () {
})

it('visits the app root url', function () {
browser.assert
.textContains('.green', 'You did it!')
.assert.elementHasCount('.wrapper nav a', 2)
.strictClick('.wrapper nav a:last-child')
browser.assert.textContains('.green', 'You did it!')
})

after((browser) => browser.end())
2 changes: 1 addition & 1 deletion template/config/playwright/e2e/vue.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { test, expect } = require('@playwright/test');
import { test, expect } from '@playwright/test';

// See here how to get started:
// https://playwright.dev/docs/intro
3 changes: 3 additions & 0 deletions template/tsconfig/cypress-ct/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"files": [],
"compilerOptions": {
"module": "es2015"
},
"references": [
{
"path": "./tsconfig.node.json"
5 changes: 3 additions & 2 deletions template/tsconfig/nightwatch/nightwatch/tsconfig.json
Original file line number Diff line number Diff line change
@@ -3,14 +3,15 @@
"compilerOptions": {
"target": "ESNext",
"module": "commonjs",
"moduleResolution": "node",
"composite": true,
"rootDir": "../",
"lib": ["ESNext", "dom"],
"types": ["nightwatch"]
},
"include": ["../node_modules/@nightwatch/**/*", "../src/components/**/*", "../tests/e2e/**/*"],
"include": ["../src/components/**/*", "../tests/e2e/**/*"],
"ts-node": {
"files": true
"transpileOnly": true
},
"files": ["nightwatch.d.ts"]
}
3 changes: 3 additions & 0 deletions template/tsconfig/vitest/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"files": [],
"compilerOptions": {
"module": "es2015"
},
"references": [
{
"path": "./tsconfig.node.json"
6 changes: 1 addition & 5 deletions utils/filterList.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
export const FILES_TO_FILTER = [
'nightwatch.e2e.conf.js',
'nightwatch.component.conf.js',
'globals.js'
]
export const FILES_TO_FILTER = []