From d2c6f0a28cd5f50170083f0c8793e047e1f7169f Mon Sep 17 00:00:00 2001 From: Jonas Amundsen Date: Wed, 25 Sep 2024 12:32:52 +0200 Subject: [PATCH] Why does this fail on Windows? --- .github/workflows/build.yml | 60 +------------ .github/workflows/examples-branch.yml | 118 -------------------------- .github/workflows/examples-master.yml | 72 ---------------- lib/subpath-entrypoints/esbuild.ts | 50 ++++++++--- 4 files changed, 42 insertions(+), 258 deletions(-) delete mode 100644 .github/workflows/examples-branch.yml delete mode 100644 .github/workflows/examples-master.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dd55878a..906b49f7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,62 +7,6 @@ concurrency: cancel-in-progress: true jobs: - prepare-versions: - runs-on: ubuntu-latest - outputs: - matrix: ${{ steps.set-matrix.outputs.matrix }} - steps: - - name: Checkout - uses: actions/checkout@v4 - - id: set-matrix - name: Prepare - run: echo "matrix=$(node -p "JSON.stringify(require('./package.json').peerDependencies['cypress'].split(' || '))")" >> $GITHUB_OUTPUT - - run: npm -v - - test: - needs: prepare-versions - runs-on: ubuntu-latest - container: - image: cypress/browsers:latest - strategy: - fail-fast: false - matrix: - cypress-version: ${{fromJson(needs.prepare-versions.outputs.matrix)}} - steps: - - uses: actions/setup-node@v4 - with: - node-version: 18 - - name: Checkout - uses: actions/checkout@v4 - - name: Cache NPM modules - uses: actions/cache@v4 - with: - path: ~/.npm - key: npm-linux@${{ matrix.cypress-version }} - - name: Cache Cypress binaries - uses: actions/cache@v4 - with: - path: ~/.cache/Cypress - key: cypress-linux@${{ matrix.cypress-version }} - - name: Change owner - run: "chown root: ." - - name: Dependencies - env: - CYPRESS_INSTALL_BINARY: "0" - run: | - npm install --engine-strict && \ - npm install --no-save cypress@${{ matrix.cypress-version }} && \ - env -u CYPRESS_INSTALL_BINARY npx cypress install - - name: Build - run: npm run build - - name: Test - run: npm run test - - name: Versions - run: | - npx cypress --version - node --version - npm --version - windows: runs-on: windows-latest env: @@ -93,7 +37,9 @@ jobs: - name: Remove Webpack test run: rm features/loaders/webpack.feature - name: Test - run: npm run test:integration + env: + DEBUG: cypress:electron,cypress-configuration,cypress-cucumber-preprocessor + run: npm run test:integration -- features\reporters\usage.feature:91 - name: Versions run: | npx cypress --version diff --git a/.github/workflows/examples-branch.yml b/.github/workflows/examples-branch.yml deleted file mode 100644 index a817ff1c..00000000 --- a/.github/workflows/examples-branch.yml +++ /dev/null @@ -1,118 +0,0 @@ -name: Examples (branch) - -on: - push: - branches-ignore: - - master - -defaults: - run: - shell: bash - -jobs: - find-examples: - runs-on: ubuntu-latest - outputs: - matrix: ${{ steps.set-matrix.outputs.matrix }} - steps: - - name: Checkout - uses: actions/checkout@v4 - - id: set-matrix - name: Prepare - run: echo "matrix=$(node -p "JSON.stringify(fs.readdirSync('examples').filter(f => f !== 'readme.md'))")" >> $GITHUB_OUTPUT - - build-package: - runs-on: ubuntu-latest - container: - image: cypress/base:latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Cache NPM modules - uses: actions/cache@v4 - with: - path: ~/.npm - key: npm-linux@latest - - name: Cache Cypress binaries - uses: actions/cache@v4 - with: - path: ~/.cache/Cypress - key: cypress-linux@latest - - name: Change owner - run: "chown root: ." - - name: Dependencies - env: - CYPRESS_INSTALL_BINARY: "0" - run: | - npm install - - name: Build - run: npm run build - - name: Pack - run: npm pack - - name: Store dirty build - uses: actions/upload-artifact@v4 - with: - name: build - path: badeball-* - - example: - needs: - - find-examples - - build-package - runs-on: ubuntu-latest - container: - image: cypress/base:latest - strategy: - fail-fast: false - matrix: - example: ${{fromJson(needs.find-examples.outputs.matrix)}} - env: - NPM_CONFIG_PACKAGE_LOCK: "false" - steps: - - uses: actions/setup-node@v4 - with: - node-version: 18 - - name: Checkout - uses: actions/checkout@v4 - - name: Cache NPM modules - uses: actions/cache@v4 - with: - path: ~/.npm - key: npm@${{ matrix.example }} - - name: Cache Cypress binaries - uses: actions/cache@v4 - with: - path: ~/.cache/Cypress - key: cypress-examples - # In lack of native support, https://github.com/actions/checkout/issues/172. - - name: Make checkout sparse - run: | - shopt -s extglob - rm -rf examples/!(${{ matrix.example }}) - rm -rf !(examples) - - name: Retrieve dirty build - uses: actions/download-artifact@v4 - with: - name: build - path: examples/${{ matrix.example }} - - name: Install NPM modules - working-directory: examples/${{ matrix.example }} - run: npm install --engine-strict badeball-* - # For reasons unknown to me, `npm install ` will not trigger postinstall scripts. - # See https://github.com/npm/cli/issues/4804. - - name: Patch packages - working-directory: examples/${{ matrix.example }} - run: npx patch-package - - name: Run Cypress - working-directory: examples/${{ matrix.example }} - run: | - if [[ "${{ matrix.example }}" == ct-* ]]; then - npx cypress run --component - else - npx cypress run --e2e - fi - - name: Versions - run: | - npx cypress --version - node --version - npm --version diff --git a/.github/workflows/examples-master.yml b/.github/workflows/examples-master.yml deleted file mode 100644 index ac147d48..00000000 --- a/.github/workflows/examples-master.yml +++ /dev/null @@ -1,72 +0,0 @@ -name: Examples (master) - -on: - push: - branches: - - master - -defaults: - run: - shell: bash - -jobs: - find-examples: - runs-on: ubuntu-latest - outputs: - matrix: ${{ steps.set-matrix.outputs.matrix }} - steps: - - name: Checkout - uses: actions/checkout@v4 - - id: set-matrix - name: Prepare - run: echo "matrix=$(node -p "JSON.stringify(fs.readdirSync('examples').filter(f => f !== 'readme.md'))")" >> $GITHUB_OUTPUT - - example: - needs: find-examples - runs-on: ubuntu-latest - container: - image: cypress/base:latest - strategy: - fail-fast: false - matrix: - example: ${{fromJson(needs.find-examples.outputs.matrix)}} - env: - NPM_CONFIG_PACKAGE_LOCK: "false" - steps: - - uses: actions/setup-node@v4 - with: - node-version: 18 - - name: Checkout - uses: actions/checkout@v4 - - name: Cache NPM modules - uses: actions/cache@v4 - with: - path: ~/.npm - key: npm@${{ matrix.example }} - - name: Cache Cypress binaries - uses: actions/cache@v4 - with: - path: ~/.cache/Cypress - key: cypress-examples - # In lack of native support, https://github.com/actions/checkout/issues/172. - - name: Make checkout sparse - run: | - shopt -s extglob - rm -rf examples/!(${{ matrix.example }}) - rm -rf !(examples) - - name: Install NPM modules - working-directory: examples/${{ matrix.example }} - run: npm install --engine-strict - - name: Run Cypress - working-directory: examples/${{ matrix.example }} - run: | - if [[ "${{ matrix.example }}" == ct-* ]]; then - npx cypress run --component - else - npx cypress run --e2e - fi - - name: Versions - run: | - npx cypress --version - node --version - npm --version diff --git a/lib/subpath-entrypoints/esbuild.ts b/lib/subpath-entrypoints/esbuild.ts index 02c77df0..de879cf9 100644 --- a/lib/subpath-entrypoints/esbuild.ts +++ b/lib/subpath-entrypoints/esbuild.ts @@ -8,6 +8,14 @@ import { compile } from "../template"; import { assertAndReturn } from "../helpers/assertions"; +import debug from "../helpers/debug"; + +const exists = (path: string) => + fs.access(path).then( + () => true, + () => false, + ); + export function createEsbuildPlugin( configuration: Cypress.PluginConfigOptions, options: { prettySourceMap: boolean } = { prettySourceMap: false }, @@ -31,15 +39,37 @@ export function createEsbuildPlugin( (await fs.readFile(sourceMapLocation)).toString(), ); - /** - * In leu of https://github.com/evanw/esbuild/issues/2218. - */ - sourceMap.sources = sourceMap.sources.map((source: string) => { - return path.relative( - configuration.projectRoot, - path.normalize(path.join(path.dirname(outfile), source)), - ); - }); + const firstSource = sourceMap.sources[0]; + + const isRelativeToProjectRoot = (file: string) => + exists(path.join(configuration.projectRoot, file)); + + const needPrettify = + firstSource != null && + !(await isRelativeToProjectRoot(firstSource)); + + debug("first source", firstSource); + debug("project root", configuration.projectRoot); + debug( + "isRelativeToProjectRoot", + await isRelativeToProjectRoot(firstSource), + ); + + if (needPrettify) { + debug("esbuild: prettifying sources"); + + /** + * In leu of https://github.com/evanw/esbuild/issues/2218. + */ + sourceMap.sources = sourceMap.sources.map((source: string) => { + return path.relative( + configuration.projectRoot, + path.normalize(path.join(path.dirname(outfile), source)), + ); + }); + } else { + debug("esbuild: normal sources"); + } await fs.rm(sourceMapLocation); @@ -47,8 +77,6 @@ export function createEsbuildPlugin( "base64", ); - console.log(encoded.length); - await fs.appendFile( outfile, `//# sourceMappingURL=data:application/json;base64,${encoded}\n`,