diff --git a/guides/esm-migration.md b/guides/esm-migration.md index f3fbae0fd9a..f9b2cd4905a 100644 --- a/guides/esm-migration.md +++ b/guides/esm-migration.md @@ -46,9 +46,8 @@ When migrating some of these projects away from the `ts-node` entry [see `@packa - [ ] packages/example - [ ] packages/extension - [ ] packages/frontend-shared **PARTIAL** - entry point is JS -- [ ] packages/https-proxy - higher priority - [x] packages/electron ✅ **COMPLETED** -- [ ] packages/https-proxy **PARTIAL** - entry point is JS +- [ ] packages/https-proxy - higher priority - [x] packages/icons ✅ **COMPLETED** - [x] packages/launcher ✅ **COMPLETED** - [x] packages/launchpad ✅ **COMPLETED** @@ -98,8 +97,7 @@ When migrating some of these projects away from the `ts-node` entry [see `@packa - [ ] packages/extension - [ ] packages/https-proxy - [x] packages/electron ✅ **COMPLETED** -- [ ] packages/https-proxy -- [ ] packages/icons +- [x] packages/icons ✅ **COMPLETED** - [ ] packages/launcher - [ ] packages/net-stubbing - [x] packages/network ✅ **COMPLETED** diff --git a/package.json b/package.json index b21b84e3edf..7d3097ad50f 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "stop-only": "npx stop-only --skip .cy,.publish,.projects,node_modules,dist,dist-test,fixtures,lib,bower_components,src,__snapshots__,patches --exclude cypress-tests.ts,*only.cy.js", "stop-only-all": "yarn stop-only --folder packages", "pretest": "yarn ensure-deps", - "test": "yarn lerna exec yarn test --scope=cypress --scope=@packages/{config,data-context,driver,electron,errors,extension,https-proxy,launcher,net-stubbing,network,packherd-require,proxy,rewriter,scaffold-config,socket,v8-snapshot-require,telemetry,stderr-filtering,types} --scope=@tooling/{electron-mksnapshot,v8-snapshot}", + "test": "yarn lerna exec yarn test --scope=cypress --scope=@packages/{config,data-context,driver,electron,errors,extension,https-proxy,icons,launcher,net-stubbing,network,packherd-require,proxy,rewriter,scaffold-config,socket,v8-snapshot-require,telemetry,stderr-filtering,types} --scope=@tooling/{electron-mksnapshot,v8-snapshot}", "test-debug": "lerna exec yarn test-debug --ignore=@packages/{driver,root,static,web-config}", "test-integration": "lerna exec yarn test-integration --ignore=@packages/{driver,root,static,web-config}", "test-mocha": "mocha --reporter spec scripts/spec.js", diff --git a/packages/icons/.eslintignore b/packages/icons/.eslintignore index 79afe972da7..90b920802dc 100644 --- a/packages/icons/.eslintignore +++ b/packages/icons/.eslintignore @@ -1,5 +1,8 @@ **/dist +index.js +index.mjs **/*.d.ts +**/*.d.mts **/package-lock.json **/tsconfig.json **/cypress/fixtures \ No newline at end of file diff --git a/packages/icons/.gitignore b/packages/icons/.gitignore new file mode 100644 index 00000000000..d6218f48241 --- /dev/null +++ b/packages/icons/.gitignore @@ -0,0 +1,5 @@ +**/dist +index.js +index.mjs +index.d.ts +index.d.mts \ No newline at end of file diff --git a/packages/icons/index.d.ts b/packages/icons/index.d.ts deleted file mode 100644 index c28237ffe77..00000000000 --- a/packages/icons/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './dist/icons' \ No newline at end of file diff --git a/packages/icons/index.js b/packages/icons/index.js deleted file mode 100644 index 472bf21cc8c..00000000000 --- a/packages/icons/index.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('./dist/icons') diff --git a/packages/icons/index.mts b/packages/icons/index.mts new file mode 100644 index 00000000000..f565ef8050c --- /dev/null +++ b/packages/icons/index.mts @@ -0,0 +1,19 @@ +import path from 'path' + +const dist = [import.meta.dirname, 'dist'] + +function distPath (...args: string[]) { + return path.join.apply(path, dist.concat([...args])) +} + +export const getPathToFavicon = (filename: string) => { + return distPath('favicon', filename) +} + +export const getPathToIcon = (filename: string) => { + return distPath('icons', filename) +} + +export const getPathToLogo = (filename: string) => { + return distPath('logo', filename) +} diff --git a/packages/icons/src/icons.ts b/packages/icons/index.ts similarity index 91% rename from packages/icons/src/icons.ts rename to packages/icons/index.ts index ef9751143c5..30c6ec4f430 100644 --- a/packages/icons/src/icons.ts +++ b/packages/icons/index.ts @@ -1,6 +1,6 @@ import path from 'path' -const dist = [__dirname, '..', 'dist'] +const dist = [__dirname, 'dist'] function distPath (...args: string[]) { return path.join.apply(path, dist.concat([...args])) diff --git a/packages/icons/package.json b/packages/icons/package.json index 246e3116e1f..29e60a32540 100644 --- a/packages/icons/package.json +++ b/packages/icons/package.json @@ -5,26 +5,32 @@ "private": true, "main": "index.js", "scripts": { - "build": "ts-node ./scripts/build.ts && ts-node ./scripts/ico.ts", - "check-ts": "tsc --noEmit && yarn -s tslint", + "build": "yarn build-assets && yarn build:cjs && yarn build:esm", + "build-assets": "tsx ./scripts/build.ts && tsx ./scripts/ico.ts", + "build-prod": "yarn build", + "build:cjs": "tsc -p tsconfig.cjs.json", + "build:esm": "tsc -p tsconfig.esm.json", + "check-ts": "tsc -p tsconfig.cjs.json --noEmit && yarn -s tslint -p tsconfig.cjs.json", "lint": "eslint --ext .js,.jsx,.ts,.tsx,.json, .", "test": "yarn test-unit", - "test-unit": "NODE_ENV=test mocha -r @packages/ts/register test/*.ts", + "test-unit": "vitest run", "tslint": "tslint --config ../ts/tslint.json --project ." }, "devDependencies": { "@types/mocha": "^8.0.3", "@types/to-ico": "^1.1.1", - "chai": "^4.2.0", "fs-extra": "9.1.0", - "mocha": "^8.1.3", - "to-ico": "^1.1.5" + "to-ico": "^1.1.5", + "tsx": "^4.20.5", + "vitest": "^3.2.4" }, "files": [ "dist", "index.js", "index.d.ts" ], + "types": "index.d.ts", "license": "MIT", + "module": "index.mjs", "nx": {} } diff --git a/packages/icons/test/icons.spec.ts b/packages/icons/test/icons.spec.ts new file mode 100644 index 00000000000..b5f53a4bef8 --- /dev/null +++ b/packages/icons/test/icons.spec.ts @@ -0,0 +1,22 @@ +import { describe, it, expect } from 'vitest' +import * as iconsESM from '../index.mjs' +import * as iconsCjs from '../index.js' + +const cwd = process.cwd() + +describe('Cypress Icons', function () { + it('returns path to favicon', function () { + expect(iconsESM.getPathToFavicon('favicon-red.ico')).toEqual(`${cwd }/dist/favicon/favicon-red.ico`) + expect(iconsCjs.getPathToFavicon('favicon-red.ico')).toEqual(`${cwd }/dist/favicon/favicon-red.ico`) + }) + + it('returns path to icon', function () { + expect(iconsESM.getPathToIcon('cypress.icns')).toEqual(`${cwd }/dist/icons/cypress.icns`) + expect(iconsCjs.getPathToIcon('cypress.icns')).toEqual(`${cwd }/dist/icons/cypress.icns`) + }) + + it('returns path to logo', function () { + expect(iconsESM.getPathToLogo('cypress-bw.png')).toEqual(`${cwd }/dist/logo/cypress-bw.png`) + expect(iconsCjs.getPathToLogo('cypress-bw.png')).toEqual(`${cwd }/dist/logo/cypress-bw.png`) + }) +}) diff --git a/packages/icons/test/icons_spec.ts b/packages/icons/test/icons_spec.ts deleted file mode 100644 index 09622d4c012..00000000000 --- a/packages/icons/test/icons_spec.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { expect } from 'chai' -import * as icons from '../src/icons' - -const cwd = process.cwd() - -describe('Cypress Icons', function () { - it('returns path to favicon', function () { - expect(icons.getPathToFavicon('favicon-red.ico')).to.eq(`${cwd }/dist/favicon/favicon-red.ico`) - }) - - it('returns path to icon', function () { - expect(icons.getPathToIcon('cypress.icns')).to.eq(`${cwd }/dist/icons/cypress.icns`) - }) - - it('returns path to logo', function () { - expect(icons.getPathToLogo('cypress-bw.png')).to.eq(`${cwd }/dist/logo/cypress-bw.png`) - }) -}) diff --git a/packages/icons/tsconfig.json b/packages/icons/tsconfig.base.json similarity index 57% rename from packages/icons/tsconfig.json rename to packages/icons/tsconfig.base.json index 315454e205a..ea2cb9d4a72 100644 --- a/packages/icons/tsconfig.json +++ b/packages/icons/tsconfig.base.json @@ -1,9 +1,10 @@ { - "extends": "../ts/tsconfig.json", "compilerOptions": { "allowJs": false, "noImplicitAny": true, "noUncheckedIndexedAccess": true, - "outDir": "dist", - }, + "skipLibCheck": true, + "esModuleInterop": true, + "declaration": true + } } diff --git a/packages/icons/tsconfig.build.json b/packages/icons/tsconfig.build.json deleted file mode 100644 index e177dd467ba..00000000000 --- a/packages/icons/tsconfig.build.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "extends": "./tsconfig.json", - "files": [ - "./src/icons.ts" - ] -} \ No newline at end of file diff --git a/packages/icons/tsconfig.cjs.json b/packages/icons/tsconfig.cjs.json new file mode 100644 index 00000000000..e335562003d --- /dev/null +++ b/packages/icons/tsconfig.cjs.json @@ -0,0 +1,11 @@ +{ + "extends": "./tsconfig.base.json", + "include": [ + "index.ts" + ], + "compilerOptions": { + "target": "ES2022", + "module": "CommonJS", + "moduleResolution": "node" + } +} \ No newline at end of file diff --git a/packages/icons/tsconfig.esm.json b/packages/icons/tsconfig.esm.json new file mode 100644 index 00000000000..6bfc1fc875c --- /dev/null +++ b/packages/icons/tsconfig.esm.json @@ -0,0 +1,12 @@ +{ + "extends": "./tsconfig.base.json", + "include": [ + "index.mts" + ], + "compilerOptions": { + "target": "ES2022", + "module": "ES2022", + "moduleResolution": "node", + "noEmit": true + } +} \ No newline at end of file diff --git a/packages/icons/vitest.config.ts b/packages/icons/vitest.config.ts new file mode 100644 index 00000000000..1a9a321880f --- /dev/null +++ b/packages/icons/vitest.config.ts @@ -0,0 +1,9 @@ +import { defineConfig } from 'vitest/config' + +export default defineConfig({ + test: { + include: ['test/**/*.spec.ts'], + globals: true, + environment: 'node', + }, +}) diff --git a/yarn.lock b/yarn.lock index 6ac4e67f682..c9288e08c76 100644 --- a/yarn.lock +++ b/yarn.lock @@ -24031,7 +24031,7 @@ mocha@7.2.0, mocha@^7.1.0: yargs-parser "13.1.2" yargs-unparser "1.6.0" -mocha@^8.1.1, mocha@^8.1.3: +mocha@^8.1.1: version "8.3.1" resolved "https://registry.yarnpkg.com/mocha/-/mocha-8.3.1.tgz#b9eda6da1eb8cb8d29860a9c2205de5b8a076560" integrity sha512-5SBMxANWqOv5bw3Hx+HVgaWlcWcFEQDUdaUAr1AUU+qwtx6cowhn7gEDT/DwQP7uYxnvShdUOVLbTYAHOEGfDQ== @@ -31953,6 +31953,16 @@ tsx@4.20.5: optionalDependencies: fsevents "~2.3.3" +tsx@^4.20.5: + version "4.20.6" + resolved "https://registry.yarnpkg.com/tsx/-/tsx-4.20.6.tgz#8fb803fd9c1f70e8ccc93b5d7c5e03c3979ccb2e" + integrity sha512-ytQKuwgmrrkDTFP4LjR0ToE2nqgy886GpvRSpU0JAnrdBYppuY5rLkRUYPU1yCryb24SsKBTL/hlDQAEFVwtZg== + dependencies: + esbuild "~0.25.0" + get-tsconfig "^4.7.5" + optionalDependencies: + fsevents "~2.3.3" + tuf-js@^2.2.1: version "2.2.1" resolved "https://registry.npmjs.org/tuf-js/-/tuf-js-2.2.1.tgz#fdd8794b644af1a75c7aaa2b197ddffeb2911b56"