Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support compileExcludes for transform #658

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/long-colts-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ice/pkg': minor
---

feat: support `compileExcludes` options for transform
2 changes: 2 additions & 0 deletions packages/pkg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"gzip-size": "^7.0.0",
"lodash.merge": "^4.6.2",
"magic-string": "^0.25.7",
"picomatch": "^2.3.1",
"picocolors": "^1.0.0",
"postcss": "^8.4.6",
"postcss-plugin-rpx2vw": "^1.0.0",
Expand All @@ -73,6 +74,7 @@
"@types/babel__core": "^7.1.20",
"@types/fs-extra": "^9.0.13",
"@types/lodash.merge": "^4.6.7",
"@types/picomatch": "^2.0.0",
"@types/node": "^17.0.2",
"cssnano": "^5.1.15",
"jest": "^29.4.3",
Expand Down
5 changes: 4 additions & 1 deletion packages/pkg/src/tasks/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type {
} from '../types.js';
import type { RollupOptions, SourceMapInput } from 'rollup';
import { getTransformEntryDirs } from '../helpers/getTaskIO.js';
import picomatch from 'picomatch';

export const watchTransformTasks: RunTasks = async (taskOptionsList, context, watcher) => {
const handleChangeFunctions: HandleChange[] = [];
Expand Down Expand Up @@ -128,6 +129,8 @@ async function runTransform(
},
});

const excludeMatcher = picomatch(userConfig?.transform?.compileExcludes ?? []);

const start = performance.now();

logger.debug('Transform start...');
Expand All @@ -150,7 +153,7 @@ async function runTransform(
let map: SourceMapInput = null;

// User should use plugins to transform other types of files.
if (loadResult === null && !INCLUDES_UTF8_FILE_TYPE.test(files[i].ext)) {
if (excludeMatcher(files[i].filePath) || (loadResult === null && !INCLUDES_UTF8_FILE_TYPE.test(files[i].ext))) {
fs.copyFileSync(files[i].absolutePath, dest);

logger.debug(`Transform file ${files[i].absolutePath}`, timeFrom(traverseFileStart));
Expand Down
4 changes: 4 additions & 0 deletions packages/pkg/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export interface TransformUserConfig {
* @see https://github.com/isaacs/minimatch
*/
excludes?: string | string[];
/**
* Exclude compiling files which are copy.
*/
compileExcludes?: string | string[];
}

export interface BundleUserConfig {
Expand Down
8 changes: 8 additions & 0 deletions packages/pkg/tests/fixtures/transform-excludes/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@ice/pkg-tests-fixtures-transform-excludes",
"version": "0.0.0",
"private": true,
"dependencies": {
"@ice/pkg": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';
const path = require('path');
console.log(path);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const title = 'index'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.foo { color: red; }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';
const path = require('path');
console.log(path);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const path = 'nested/n1'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const path = 'nested/n2'
Original file line number Diff line number Diff line change
@@ -0,0 +1,305 @@
// Vitest Snapshot v1

exports[`Run config compile-excludes > cjs structure 1`] = `
{
"files": [
{
"name": "index.js",
},
{
"name": "index.min.js",
},
{
"files": [
{
"name": "n1.js",
},
{
"name": "n1.less",
},
{
"name": "n1.min.js",
},
{
"name": "n2.js",
},
],
"name": "nested",
},
],
"name": "cjs",
}
`;

exports[`Run config compile-excludes > dist structure 1`] = `null`;

exports[`Run config compile-excludes > es2017 structure 1`] = `
{
"files": [
{
"name": "index.js",
},
{
"name": "index.min.js",
},
{
"files": [
{
"name": "n1.js",
},
{
"name": "n1.less",
},
{
"name": "n1.min.js",
},
{
"name": "n2.js",
},
],
"name": "nested",
},
],
"name": "es2017",
}
`;

exports[`Run config compile-excludes > esm structure 1`] = `
{
"files": [
{
"name": "index.js",
},
{
"name": "index.min.js",
},
{
"files": [
{
"name": "n1.js",
},
{
"name": "n1.less",
},
{
"name": "n1.min.js",
},
{
"name": "n2.js",
},
],
"name": "nested",
},
],
"name": "esm",
}
`;

exports[`Run config compile-excludes > file content cjs/index.js 1`] = `
"\\"use strict\\";
Object.defineProperty(exports, \\"__esModule\\", {
value: true
});
Object.defineProperty(exports, \\"title\\", {
enumerable: true,
get: function() {
return title;
}
});
var title = \\"index\\";
"
`;

exports[`Run config compile-excludes > file content cjs/index.min.js 1`] = `
"'use strict';
const path = require('path');
console.log(path);
"
`;

exports[`Run config compile-excludes > file content cjs/nested/n1.js 1`] = `
"\\"use strict\\";
Object.defineProperty(exports, \\"__esModule\\", {
value: true
});
Object.defineProperty(exports, \\"path\\", {
enumerable: true,
get: function() {
return path;
}
});
var path = \\"nested/n1\\";
"
`;

exports[`Run config compile-excludes > file content cjs/nested/n1.less 1`] = `
".foo { color: red; }
"
`;

exports[`Run config compile-excludes > file content cjs/nested/n1.min.js 1`] = `
"'use strict';
const path = require('path');
console.log(path);
"
`;

exports[`Run config compile-excludes > file content cjs/nested/n2.js 1`] = `
"\\"use strict\\";
Object.defineProperty(exports, \\"__esModule\\", {
value: true
});
Object.defineProperty(exports, \\"path\\", {
enumerable: true,
get: function() {
return path;
}
});
var path = \\"nested/n2\\";
"
`;

exports[`Run config compile-excludes > file content es2017/index.js 1`] = `
"export const title = 'index';
"
`;

exports[`Run config compile-excludes > file content es2017/index.min.js 1`] = `
"'use strict';
const path = require('path');
console.log(path);
"
`;

exports[`Run config compile-excludes > file content es2017/nested/n1.js 1`] = `
"export const path = 'nested/n1';
"
`;

exports[`Run config compile-excludes > file content es2017/nested/n1.less 1`] = `
".foo { color: red; }
"
`;

exports[`Run config compile-excludes > file content es2017/nested/n1.min.js 1`] = `
"'use strict';
const path = require('path');
console.log(path);
"
`;

exports[`Run config compile-excludes > file content es2017/nested/n2.js 1`] = `
"export const path = 'nested/n2';
"
`;

exports[`Run config compile-excludes > file content esm/index.js 1`] = `
"export var title = \\"index\\";
"
`;

exports[`Run config compile-excludes > file content esm/index.min.js 1`] = `
"'use strict';
const path = require('path');
console.log(path);
"
`;

exports[`Run config compile-excludes > file content esm/nested/n1.js 1`] = `
"export var path = \\"nested/n1\\";
"
`;

exports[`Run config compile-excludes > file content esm/nested/n1.less 1`] = `
".foo { color: red; }
"
`;

exports[`Run config compile-excludes > file content esm/nested/n1.min.js 1`] = `
"'use strict';
const path = require('path');
console.log(path);
"
`;

exports[`Run config compile-excludes > file content esm/nested/n2.js 1`] = `
"export var path = \\"nested/n2\\";
"
`;

exports[`Run config excludes > cjs structure 1`] = `
{
"files": [
{
"name": "index.js",
},
{
"name": "index.min.js",
},
{
"files": [
{
"name": "n1.less",
},
{
"name": "n1.min.js",
},
],
"name": "nested",
},
],
"name": "cjs",
}
`;

exports[`Run config excludes > dist structure 1`] = `null`;

exports[`Run config excludes > es2017 structure 1`] = `
{
"files": [
{
"name": "index.js",
},
{
"name": "index.min.js",
},
{
"files": [
{
"name": "n1.less",
},
{
"name": "n1.min.js",
},
],
"name": "nested",
},
],
"name": "es2017",
}
`;

exports[`Run config excludes > esm structure 1`] = `
{
"files": [
{
"name": "index.js",
},
{
"name": "index.min.js",
},
{
"files": [
{
"name": "n1.less",
},
{
"name": "n1.min.js",
},
],
"name": "nested",
},
],
"name": "esm",
}
`;
Loading
Loading