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: add ignore option to ignore files from build #68

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,12 +600,14 @@ export async function exec(argv2: string[]) {
if (configJson) {
marker = {
config: configJson,
toplevelConfig: configJson,
robertsLando marked this conversation as resolved.
Show resolved Hide resolved
base: path.dirname(config),
configPath: config,
};
} else {
marker = {
config: inputJson || {}, // not `inputBin` because only `input`
toplevelConfig: inputJson || {},
base: path.dirname(input), // is the place for `inputJson`
configPath: input,
};
Expand Down
1 change: 1 addition & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface PkgOptions {
scripts?: string[];
log?: (logger: typeof log, context: Record<string, string>) => void;
assets?: string[];
ignore?: string[];
deployFiles?: string[];
patches?: Patches;
dictionary: ConfigDictionary;
Expand Down
23 changes: 22 additions & 1 deletion lib/walker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface Marker {
hasDictionary?: boolean;
activated?: boolean;
toplevel?: boolean;
toplevelConfig: PackageJson;
public?: boolean;
hasDeployFiles?: boolean;
config?: PackageJson;
Expand Down Expand Up @@ -450,6 +451,21 @@ class Walker {
assert(typeof task.file === 'string');
const realFile = toNormalizedRealPath(task.file);

const ignore = task.marker?.toplevelConfig.pkg?.ignore;
if (ignore) {
// check if the file matches one of the ignore regex patterns
const match = ignore.some((pattern) =>
new RegExp(pattern).test(realFile),
);

if (match) {
log.debug(
`Ignoring file: ${realFile} due to top level config ignore pattern`,
);
return;
}
Mikescops marked this conversation as resolved.
Show resolved Hide resolved
}

if (realFile === task.file) {
this.append(task);
return;
Expand Down Expand Up @@ -747,7 +763,12 @@ class Walker {

const catchPackageFilter = (config: PackageJson, base: string) => {
const newPackage = newPackages[newPackages.length - 1];
newPackage.marker = { config, configPath: newPackage.packageJson, base };
newPackage.marker = {
config,
configPath: newPackage.packageJson,
base,
toplevelConfig: marker.toplevelConfig,
};
};

let newFile = '';
Expand Down
1 change: 1 addition & 0 deletions test/test-50-ignore-files/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!node_modules
49 changes: 49 additions & 0 deletions test/test-50-ignore-files/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env node

'use strict';

const path = require('path');
const assert = require('assert');
const utils = require('../utils.js');
const standard = 'stdout';

assert(!module.parent);
assert(__dirname === process.cwd());

const target = process.argv[2] || 'host';
const output = './test-output.exe';

let left, right;
utils.mkdirp.sync(path.dirname(output));

left = utils.spawn.sync('node', ['test-x-index.js']);

const inspect =
standard === 'stdout'
? ['inherit', 'pipe', 'inherit']
: ['inherit', 'inherit', 'pipe'];

const log = utils.pkg.sync(
['--target', target, '--output', output, '.', '--debug'],
inspect,
);

assert(
log.indexOf(
'node_modules/delta/useless.c due to top level config ignore pattern',
) > 0,
'useless.c file is not ignored',
);
assert(
log.indexOf(
'node_modules/delta/needed.c is added to queue',
'needed.c file is not added to queue',
),
);

right = utils.spawn.sync('./' + path.basename(output), [], {
cwd: path.dirname(output),
});

assert.strictEqual(left, right);
utils.vacuum.sync(output);
3 changes: 3 additions & 0 deletions test/test-50-ignore-files/node_modules/delta/index.js

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

1 change: 1 addition & 0 deletions test/test-50-ignore-files/node_modules/delta/needed.c

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

5 changes: 5 additions & 0 deletions test/test-50-ignore-files/node_modules/delta/package.json

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

1 change: 1 addition & 0 deletions test/test-50-ignore-files/node_modules/delta/useless.c

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

12 changes: 12 additions & 0 deletions test/test-50-ignore-files/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"bin": "test-x-index.js",
"license": "MIT",
"dependencies": {
"delta": "*"
},
"pkg": {
"ignore": [
"/node_modules/delta/useless.c"
]
}
}
5 changes: 5 additions & 0 deletions test/test-50-ignore-files/test-x-index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

var dataPath = 'delta';
require(dataPath);
console.log(global.FOO);
Loading