Skip to content

Commit

Permalink
feat(compiler): allow ignore pattern for copy task (#5899)
Browse files Browse the repository at this point in the history
* feat: allow ignore pattern for copy task

* add tests to pipeline

* fix code docs

* remove unnecessary files

* add workflow to pipeline

* add missing script

* fix end-to-end tests

* prettier

* revert some changes

* set absolute flag

* use rimraf for support in Windows

* chore(deps): install Jest dependencies via TypeScript and Node

* fix task for windows

* make it relative to source path

* tweak
  • Loading branch information
christian-bromann authored Aug 8, 2024
1 parent 70c4e8a commit f89c6a3
Show file tree
Hide file tree
Showing 21 changed files with 973 additions and 58 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ jobs:
needs: [build_core]
uses: ./.github/workflows/test-bundlers.yml

copytask_tests:
name: Copy Task Tests
needs: [build_core]
uses: ./.github/workflows/test-copytask.yml

component_starter_tests:
name: Component Starter Smoke Test
needs: [build_core]
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/test-copytask.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Copy Task Tests

on:
workflow_call:
# Make this a reusable workflow, no value needed
# https://docs.github.com/en/actions/using-workflows/reusing-workflows

jobs:
bundler_tests:
name: Verify Copy Task
runs-on: 'ubuntu-22.04'
steps:
- name: Checkout Code
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6

- name: Get Core Dependencies
uses: ./.github/workflows/actions/get-core-dependencies

- name: Download Build Archive
uses: ./.github/workflows/actions/download-archive
with:
name: stencil-core
path: .
filename: stencil-core-build.zip

- name: Bundler Tests
run: npm run test.copytask
shell: bash

- name: Check Git Context
uses: ./.github/workflows/actions/check-git-context
205 changes: 184 additions & 21 deletions package-lock.json

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

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@
"build": "npm run clean && npm run tsc.prod && npm run ts scripts/index.ts -- --prod --ci",
"build.watch": "npm run build -- --watch",
"build.updateSelectorEngine": "npm run ts scripts/updateSelectorEngine.ts",
"clean": "rm -rf build/ cli/ compiler/ dev-server/ internal/ mock-doc/ sys/ testing/ && npm run clean:scripts && npm run clean.screenshots",
"clean.screenshots": "rm -rf test/end-to-end/screenshot/builds test/end-to-end/screenshot/images",
"clean:scripts": "rm -rf scripts/build",
"clean": "rimraf build/ cli/ compiler/ dev-server/ internal/ mock-doc/ sys/ testing/ && npm run clean:scripts && npm run clean.screenshots",
"clean.screenshots": "rimraf test/end-to-end/screenshot/builds test/end-to-end/screenshot/images",
"clean:scripts": "rimraf scripts/build",
"lint": "eslint 'bin/*' 'scripts/*.ts' 'scripts/**/*.ts' 'src/*.ts' 'src/**/*.ts' 'src/**/*.tsx' 'test/wdio/**/*.tsx'",
"install.jest": "npx tsx ./src/testing/jest/install-dependencies.mts",
"prettier": "npm run prettier.base -- --write",
Expand All @@ -112,6 +112,7 @@
"test": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js --coverage",
"test.analysis": "cd test && npm run analysis.build-and-analyze",
"test.bundlers": "cd test && npm run bundlers",
"test.copytask": "cd test/copy-task && npm ci && npm run test",
"test.dist": "npm run ts scripts/index.ts -- --validate-build",
"test.end-to-end": "cd test/end-to-end && npm ci && npm test && npm run test.dist",
"test.jest": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js",
Expand Down Expand Up @@ -184,6 +185,7 @@
"prettier": "3.3.1",
"prompts": "2.4.2",
"puppeteer": "^21.0.0",
"rimraf": "^6.0.1",
"rollup": "2.56.3",
"semver": "^7.3.7",
"terser": "5.31.1",
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/output-targets/copy/assets-copy-tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const getComponentAssetsCopyTasks = (
src: assetsMeta.absolutePath,
dest: join(dest, assetsMeta.cmpRelativePath),
warn: false,
ignore: undefined,
keepDirStructure: false,
});
});
Expand All @@ -37,6 +38,7 @@ export const getComponentAssetsCopyTasks = (
src: assetsMeta.absolutePath,
dest: collectionDirDestination,
warn: false,
ignore: undefined,
keepDirStructure: false,
});
});
Expand Down
12 changes: 12 additions & 0 deletions src/compiler/output-targets/copy/output-copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ import type * as d from '../../../declarations';
import { canSkipAssetsCopy, getComponentAssetsCopyTasks } from './assets-copy-tasks';
import { getDestAbsPath, getSrcAbsPath } from './local-copy-tasks';

const DEFAULT_IGNORE = [
'**/__mocks__/**',
'**/__fixtures__/**',
'**/dist/**',
'**/.{idea,git,cache,output,temp}/**',
'**/.ds_store',
'**/.gitignore',
'**/desktop.ini',
'**/thumbs.db',
];

export const outputCopy = async (config: d.ValidatedConfig, compilerCtx: d.CompilerCtx, buildCtx: d.BuildCtx) => {
const outputTargets = config.outputTargets.filter(isOutputTargetCopy);
if (outputTargets.length === 0) {
Expand Down Expand Up @@ -83,6 +94,7 @@ const transformToAbs = (copyTask: d.CopyTask, dest: string): Required<d.CopyTask
return {
src: copyTask.src,
dest: getDestAbsPath(copyTask.src, dest, copyTask.dest),
ignore: copyTask.ignore || DEFAULT_IGNORE,
keepDirStructure:
typeof copyTask.keepDirStructure === 'boolean' ? copyTask.keepDirStructure : copyTask.dest == null,
warn: copyTask.warn !== false,
Expand Down
Loading

0 comments on commit f89c6a3

Please sign in to comment.