diff --git a/.eslintrc.cjs b/.eslintrc.cjs index d567c3fd55..9605ba44c3 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -17,6 +17,9 @@ module.exports = { { files: ['**/e2e/**/*.cy.ts', '**/e2e/cypress/**/*.ts'], extends: 'plugin:cypress/recommended', + rules: { + '@typescript-eslint/no-namespace': 'off', + }, }, { files: ['**/tests/**/*.ts', 'tsup.config.ts'], diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 9ee9665327..741f8dee7a 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -64,6 +64,7 @@ jobs: env: E2E_BASE: ${{ matrix.base }} E2E_BUNDLER: ${{ matrix.bundler }} + E2E_COMMAND: dev - name: E2E build working-directory: ./e2e @@ -71,6 +72,7 @@ jobs: env: E2E_BASE: ${{ matrix.base }} E2E_BUNDLER: ${{ matrix.bundler }} + E2E_COMMAND: build e2e-result: if: ${{ always() }} diff --git a/e2e/cypress.config.ts b/e2e/cypress.config.ts index 0c0d5f6ff6..2f461f3bdd 100644 --- a/e2e/cypress.config.ts +++ b/e2e/cypress.config.ts @@ -7,5 +7,6 @@ export default defineConfig({ }, env: { E2E_BASE: process.env.E2E_BASE ?? '/', + E2E_COMMAND: process.env.E2E_COMMAND ?? 'dev', }, }) diff --git a/e2e/cypress/support/commands.ts b/e2e/cypress/support/commands.ts index 402910dd1a..06bd28ad88 100644 --- a/e2e/cypress/support/commands.ts +++ b/e2e/cypress/support/commands.ts @@ -1,8 +1,34 @@ const URL_PREFIX = Cypress.env('E2E_BASE').replace(/\/$/, '') // override the default cy.visit command to prepend base -// @ts-expect-error: could not type this method correctly -Cypress.Commands.overwrite('visit', (originalFn, url, options) => - // @ts-expect-error: could not type this method correctly - originalFn(`${URL_PREFIX}${url}`, options), +Cypress.Commands.overwrite('visit', (originalFn, ...args) => { + // cy.visit(url, options) + if (typeof args[0] === 'string') { + // @ts-expect-error: could not type this correctly + return originalFn(`${URL_PREFIX}${args[0]}`, args[1]) + } + + // cy.visit(options) + return originalFn({ + ...args[0], + url: `${URL_PREFIX}${args[0].url}`, + }) +}) + +// add a custom request command to prepend base +Cypress.Commands.add('requestWithBase', (url, options) => + cy.request(`${URL_PREFIX}${url}`, options), ) + +declare global { + namespace Cypress { + interface Chainable { + requestWithBase: ( + url: string, + options?: Partial, + ) => Chainable> + } + } +} + +export {} diff --git a/e2e/docs/imports/conditional-exports.md b/e2e/docs/imports/conditional-exports.md new file mode 100644 index 0000000000..0e1095c390 --- /dev/null +++ b/e2e/docs/imports/conditional-exports.md @@ -0,0 +1,5 @@ + + +{{ str }} diff --git a/e2e/modules/conditional-exports/browser.mjs b/e2e/modules/conditional-exports/browser.mjs new file mode 100644 index 0000000000..219fecfae0 --- /dev/null +++ b/e2e/modules/conditional-exports/browser.mjs @@ -0,0 +1 @@ +export default 'browser-mjs' diff --git a/e2e/modules/conditional-exports/node.cjs b/e2e/modules/conditional-exports/node.cjs new file mode 100644 index 0000000000..2425908ced --- /dev/null +++ b/e2e/modules/conditional-exports/node.cjs @@ -0,0 +1 @@ +module.exports = 'node-cjs' diff --git a/e2e/modules/conditional-exports/node.mjs b/e2e/modules/conditional-exports/node.mjs new file mode 100644 index 0000000000..2feb11a0cd --- /dev/null +++ b/e2e/modules/conditional-exports/node.mjs @@ -0,0 +1 @@ +export default 'node-mjs' diff --git a/e2e/modules/conditional-exports/package.json b/e2e/modules/conditional-exports/package.json new file mode 100644 index 0000000000..8343fe0c1f --- /dev/null +++ b/e2e/modules/conditional-exports/package.json @@ -0,0 +1,19 @@ +{ + "name": "@vuepress-e2e/conditional-exports", + "type": "module", + "exports": { + ".": { + "types": "./types.d.ts", + "browser": "./browser.mjs", + "node": "./node.mjs", + "module": "./node.mjs", + "import": "./node.mjs", + "require": "./node.cjs", + "default": "./node.cjs" + }, + "./*": "./*" + }, + "main": "cjs.js", + "module": "esm.js", + "types": "types.d.ts" +} diff --git a/e2e/modules/conditional-exports/types.d.ts b/e2e/modules/conditional-exports/types.d.ts new file mode 100644 index 0000000000..657d2a74ff --- /dev/null +++ b/e2e/modules/conditional-exports/types.d.ts @@ -0,0 +1,2 @@ +declare const str: string +export default str diff --git a/e2e/package.json b/e2e/package.json index f3f04b12df..c3dedf1de0 100644 --- a/e2e/package.json +++ b/e2e/package.json @@ -4,18 +4,19 @@ "private": true, "type": "module", "scripts": { - "e2e:build": "vuepress build docs --clean-cache --clean-temp", + "e2e:build": "E2E_COMMAND=build vuepress build docs --clean-cache --clean-temp", "e2e:build-webpack": "E2E_BUNDLER=webpack pnpm e2e:build", "e2e:ci:build": "pnpm e2e:build && start-server-and-test e2e:serve http-get://localhost:9080 e2e:run", "e2e:ci:dev": "start-server-and-test e2e:dev http-get://127.0.0.1:9080 e2e:run", "e2e:clean": "rimraf docs/.vuepress/.temp docs/.vuepress/.cache docs/.vuepress/dist", - "e2e:dev": "vuepress dev docs --clean-cache --clean-temp", + "e2e:dev": "E2E_COMMAND=dev vuepress dev docs --clean-cache --clean-temp", "e2e:dev-webpack": "E2E_BUNDLER=webpack pnpm e2e:dev", "e2e:open": "cypress open", "e2e:run": "cypress run", "e2e:serve": "anywhere -s -h localhost -p 9080 -d docs/.vuepress/dist" }, "dependencies": { + "@vuepress-e2e/conditional-exports": "file:./modules/conditional-exports", "@vuepress/bundler-vite": "workspace:*", "@vuepress/bundler-webpack": "workspace:*", "sass": "^1.70.0", diff --git a/e2e/tests/imports/conditional-exports.cy.ts b/e2e/tests/imports/conditional-exports.cy.ts new file mode 100644 index 0000000000..d3abd47303 --- /dev/null +++ b/e2e/tests/imports/conditional-exports.cy.ts @@ -0,0 +1,13 @@ +it('should support visiting non-ASCII paths directly', () => { + const E2E_COMMAND = Cypress.env('E2E_COMMAND') + + cy.visit('/imports/conditional-exports.html') + + cy.get('.e2e-theme-content p').should('have.text', 'browser-mjs') + + if (E2E_COMMAND === 'build') { + cy.requestWithBase('/imports/conditional-exports.html') + .its('body') + .should('include', '

node-mjs

') + } +}) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c19e97b8ed..37ffe8784a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -77,6 +77,9 @@ importers: e2e: dependencies: + '@vuepress-e2e/conditional-exports': + specifier: file:./modules/conditional-exports + version: file:e2e/modules/conditional-exports '@vuepress/bundler-vite': specifier: workspace:* version: link:../packages/bundler-vite @@ -9068,3 +9071,8 @@ packages: resolution: {integrity: sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==} engines: {node: '>=12.20'} dev: true + + file:e2e/modules/conditional-exports: + resolution: {directory: e2e/modules/conditional-exports, type: directory} + name: '@vuepress-e2e/conditional-exports' + dev: false