From 08de31478ecf77e50a3f5cde347dc373764038db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Nikoli=C4=87?= Date: Sat, 23 Mar 2024 16:06:25 +0100 Subject: [PATCH] Update files to ESM format --- generators/app/templates/karma.conf.js | 26 +++++++++---------- generators/app/templates/rollup.config.js | 24 ++++++++--------- generators/app/templates/test/manual/index.js | 1 - .../templates/test/manual/rollup.config.js | 26 +++++++++---------- .../templates/test/manual/webpack.config.js | 23 ++++++++-------- generators/app/templates/wdio.conf.js | 20 +++++++------- 6 files changed, 55 insertions(+), 65 deletions(-) diff --git a/generators/app/templates/karma.conf.js b/generators/app/templates/karma.conf.js index 6391572..824d2de 100644 --- a/generators/app/templates/karma.conf.js +++ b/generators/app/templates/karma.conf.js @@ -1,16 +1,14 @@ -'use strict'; - -const path = require('path');<% if ( codeCoverage ) { %> -const fs = require('fs');<% } %><% if ( bundlingTool === 'webpack' ) { %> -const stdLibBrowser = require('node-stdlib-browser');<% } %><% if ( bundlingTool === 'rollup' ) { %> -const { default: resolve } = require('@rollup/plugin-node-resolve'); -const commonjs = require('@rollup/plugin-commonjs'); -const nodeBuiltins = require('rollup-plugin-node-builtins'); -const globals = require('rollup-plugin-node-globals');<% if ( transpile ) { %> -const { default: babel } = require('@rollup/plugin-babel');<% } %><% if ( codeCoverage ) { %> -const istanbul = require('rollup-plugin-istanbul');<% } %> -const rollupConfig = require('./rollup.config');<% } %><% if ( browserTestType === 'headless' ) { %> -const puppeteer = require('puppeteer'); +import path from 'node:path';<% if ( codeCoverage ) { %> +import fs from 'node:fs';<% } %><% if ( bundlingTool === 'webpack' ) { %> +import stdLibBrowser from 'node-stdlib-browser';<% } %><% if ( bundlingTool === 'rollup' ) { %> +import resolve from '@rollup/plugin-node-resolve'; +import commonjs from '@rollup/plugin-commonjs'; +import nodeBuiltins from 'rollup-plugin-node-builtins'; +import globals from 'rollup-plugin-node-globals';<% if ( transpile ) { %> +import babel from '@rollup/plugin-babel';<% } %><% if ( codeCoverage ) { %> +import istanbul from 'rollup-plugin-istanbul';<% } %> +import rollupConfig from './rollup.config.js';<% } %><% if ( browserTestType === 'headless' ) { %> +import puppeteer from 'puppeteer'; process.env.CHROME_BIN = puppeteer.executablePath();<% } %> @@ -52,7 +50,7 @@ if ( local ) { }; } -module.exports = function ( baseConfig ) { +export default function ( baseConfig ) { baseConfig.set(Object.assign({ basePath: '', diff --git a/generators/app/templates/rollup.config.js b/generators/app/templates/rollup.config.js index f59a0b1..059a17e 100644 --- a/generators/app/templates/rollup.config.js +++ b/generators/app/templates/rollup.config.js @@ -1,17 +1,15 @@ -'use strict';<% if ( transpile ) { %> +<% if ( transpile ) { %>import babel from '@rollup/plugin-babel';<% } %><% if ( vanillaJsWidget ) { %> +import path from 'node:path'; +import svelte from 'rollup-plugin-svelte'; +import babelCore from '@babel/core';<% } %><% if ( typescript ) { %> +import execa from 'execa'; +import cpy from 'cpy';<% if ( !transpile && typescriptMode === 'full' ) { %> +import typescript from '@rollup/plugin-typescript';<% } %><% if ( transpile && typescriptMode === 'full' ) { %> +import resolve from '@rollup/plugin-node-resolve';<% } %><% } %> +import path from 'node:path'; +import { promises as fs } from 'node:fs'; -const { default: babel } = require('@rollup/plugin-babel');<% } %><% if ( vanillaJsWidget ) { %> -const path = require('path'); -const svelte = require('rollup-plugin-svelte'); -const babelCore = require('@babel/core');<% } %><% if ( typescript ) { %> -const execa = require('execa'); -const cpy = require('cpy');<% if ( !transpile && typescriptMode === 'full' ) { %> -const typescript = require('@rollup/plugin-typescript');<% } %><% if ( transpile && typescriptMode === 'full' ) { %> -const { default: resolve } = require('@rollup/plugin-node-resolve');<% } %><% } %> -const path = require('path'); -const { promises: fs } = require('fs'); - -module.exports = { +export default { input: '<% if ( complexTranspile ) { %>src/<% } %>index.<%= extension || 'js' %>', output: [<% if ( bundleCjs ) { %> { diff --git a/generators/app/templates/test/manual/index.js b/generators/app/templates/test/manual/index.js index ad9a93a..e69de29 100644 --- a/generators/app/templates/test/manual/index.js +++ b/generators/app/templates/test/manual/index.js @@ -1 +0,0 @@ -'use strict'; diff --git a/generators/app/templates/test/manual/rollup.config.js b/generators/app/templates/test/manual/rollup.config.js index e1c7470..d52508d 100644 --- a/generators/app/templates/test/manual/rollup.config.js +++ b/generators/app/templates/test/manual/rollup.config.js @@ -1,16 +1,14 @@ -'use strict'; - -const path = require('path'); -const del = require('del'); -const globby = require('globby'); -const minimist = require('minimist'); -const staticSite = require('rollup-plugin-static-site'); -const postcss = require('rollup-plugin-postcss'); -const serve = require('rollup-plugin-serve');<% if ( transpile ) { %> -const { default: babel } = require('@rollup/plugin-babel');<% } %><% if ( !transpile && typescript && typescriptMode === 'full' ) { %> -const typescript = require('@rollup/plugin-typescript');<% } %> -const atImport = require('postcss-import'); -const postcssPresetEnv = require('postcss-preset-env'); +import path from 'node:path'; +import del from 'del'; +import globby from 'globby'; +import minimist from 'minimist'; +import staticSite from 'rollup-plugin-static-site'; +import postcss from 'rollup-plugin-postcss'; +import serve from 'rollup-plugin-serve';<% if ( transpile ) { %> +import babel from '@rollup/plugin-babel';<% } %><% if ( !transpile && typescript && typescriptMode === 'full' ) { %> +import typescript from '@rollup/plugin-typescript';<% } %> +import atImport from 'postcss-import'; +import postcssPresetEnv from 'postcss-preset-env'; const args = minimist(process.argv.slice(2), { 'default': { @@ -87,4 +85,4 @@ const config = async () => { }; -module.exports = config(); +export default config(); diff --git a/generators/app/templates/test/manual/webpack.config.js b/generators/app/templates/test/manual/webpack.config.js index 6446cea..b5af62c 100644 --- a/generators/app/templates/test/manual/webpack.config.js +++ b/generators/app/templates/test/manual/webpack.config.js @@ -1,14 +1,13 @@ -'use strict'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; +import del from 'del'; +import globby from 'globby'; +import HtmlWebpackPlugin from 'html-webpack-plugin'; +import MiniCssExtractPlugin from 'mini-css-extract-plugin'; +import atImport from 'postcss-import'; +import postcssPresetEnv from 'postcss-preset-env'; -const path = require('path'); -const del = require('del'); -const globby = require('globby'); -const HtmlWebpackPlugin = require('html-webpack-plugin'); -const MiniCssExtractPlugin = require('mini-css-extract-plugin'); -const atImport = require('postcss-import'); -const postcssPresetEnv = require('postcss-preset-env'); - -module.exports = async () => { +export default async () => { const port = 0; @@ -32,12 +31,12 @@ module.exports = async () => { entry: entries, output: { filename: '[name].js', - path: path.resolve(__dirname, '../../test-dist'), + path: fileURLToPath(new URL('../../test-dist', import.meta.url)), }, mode: 'none', devtool: 'inline-source-map', devServer: { - contentBase: path.join(__dirname, '../../test-dist'), + contentBase: fileURLToPath(new URL('../../test-dist', import.meta.url)), port: port, host: '0.0.0.0', disableHostCheck: true, diff --git a/generators/app/templates/wdio.conf.js b/generators/app/templates/wdio.conf.js index 99e3ff0..3d09c96 100644 --- a/generators/app/templates/wdio.conf.js +++ b/generators/app/templates/wdio.conf.js @@ -1,18 +1,16 @@ -'use strict'; +import path from 'node:path'; +import http from 'node:http'; +import ws from 'local-web-server'; +import shutdown from 'http-shutdown'; -const path = require('path'); -const http = require('http'); -const ws = require('local-web-server'); -const shutdown = require('http-shutdown'); - -let server, config; +let server, _config; // Pull requests not handled as in case of Karma const local = <% if ( cloudBrowsers ) { %>typeof process.env.CI === 'undefined' || process.env.CI === 'false'<% } else { %>true<% } %>; const port = 0; if ( local ) { - config = { + _config = { baseUrl: `http://host.docker.internal:${port}`, services: [[ 'docker', { @@ -32,7 +30,7 @@ if ( local ) { }] }; }<% if ( cloudBrowsers ) { %> else { - config = { + _config = { baseUrl: `http://localhost:${port}`, user: process.env.BROWSER_STACK_USERNAME, key: process.env.BROWSER_STACK_ACCESS_KEY, @@ -50,7 +48,7 @@ if ( local ) { }; }<% } %> -module.exports.config = Object.assign({ +export const config = Object.assign({ specs: [ './test/integration/**/*.<%= extension || 'js' %>' ], @@ -113,4 +111,4 @@ module.exports.config = Object.assign({ }); } -}, config); +}, _config);