Skip to content

Commit

Permalink
feat: support hashbang
Browse files Browse the repository at this point in the history
  • Loading branch information
Airkro committed May 6, 2024
1 parent 2096944 commit 804c4da
Show file tree
Hide file tree
Showing 8 changed files with 3,478 additions and 2,614 deletions.
2 changes: 0 additions & 2 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
enable-pre-post-scripts = true
shamefully-hoist = true
node-linker = hoisted
47 changes: 35 additions & 12 deletions lib/parse.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,42 @@ function stringOrObject(from) {
return typeof from === 'string' ? { from } : from;
}

const ignore = [
'**/.{cache,git,svn,ssh,yarn}/**',
'**/.{npm,yarn}rc',
'**/.env.*',
'**/.env',
'**/.git{keep,ignore}',
'**/{node,web}_modules/**',
'**/*.{pem,ppk}',
'**/id_{d,r}sa',
'**/ssh*config',
'**/sshd*config',
];

const globOptions = {
dot: true,
gitignore: true,
ignore,
};

function parse(options) {
return toArray(options).map((from) =>
deepmerge(
{
globOptions: {
dot: true,
gitignore: true,
ignore: ['.gitkeep', '.{cache,git,svn}/**'],
},
},
stringOrObject(from),
),
);
return toArray(options)
.map((from) => deepmerge({ globOptions }, stringOrObject(from)))
.map((group) =>
group.hashbang && /(bin|cli)\.[cm]js/.test(group.from)
? {
...group,
transform(content, path) {
const io = group.transform
? group.transform(content, path)
: content.toString();

return `#!/usr/bin/env node\n${io}`;
},
}
: group,
);
}

module.exports = { parse };
7 changes: 6 additions & 1 deletion lib/schema.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ const oneOf = [
{
type: 'object',
required: ['from'],
properties: { from },
properties: {
from,
hashbang: {
type: 'boolean',
},
},
},
];

Expand Down
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "copy-webpack",
"version": "3.0.0",
"version": "4.0.0",
"description": "A simple `copy-webpack-plugin`",
"license": "MIT",
"author": {
Expand Down Expand Up @@ -29,6 +29,7 @@
"lint:staged": "nice-move lint staged",
"prepare": "nice-move git hooks",
"prepublishOnly": "pnpm run lint:staged && pnpm test",
"snapshot": "ava --fail-fast -u -w",
"test": "ava --fail-fast"
},
"dependencies": {
Expand All @@ -38,26 +39,26 @@
},
"devDependencies": {
"@bring-it/npm": "^0.5.2",
"@nice-move/cli": "^0.11.3",
"@nice-move/eslint-config-base": "^0.11.1",
"@nice-move/prettier-config": "^0.10.0",
"ava": "^6.1.2",
"@nice-move/cli": "^0.11.11",
"@nice-move/eslint-config-base": "^0.11.6",
"@nice-move/prettier-config": "^0.11.3",
"ava": "^6.1.3",
"eslint": "^8.57.0",
"eslint-plugin-ava": "^14.0.0",
"garou": "^0.7.0",
"garou": "^0.7.4",
"prettier": "^3.2.5"
},
"peerDependencies": {
"webpack": "^5.90.3"
},
"packageManager": "[email protected]",
"engines": {
"node": ">=20.0.0 || ^18.12.0"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
},
"packageManager": "[email protected]",
"eslintConfig": {
"extends": "@nice-move/eslint-config-base"
},
Expand Down
Loading

0 comments on commit 804c4da

Please sign in to comment.