feat: publishConfig.executableFiles (#3628)

This commit is contained in:
Zoltan Kochan authored and GitHub committed 2021-07-30 11:19:10 +03:00
1 parent bc36a0055f
commit b734b45ea2
8 files changed
+38 -4

No files matched your search

+13
View File
@@ -0,0 +1,13 @@
---
"@pnpm/plugin-commands-publishing": minor
---
By default, for portability reasons, no files except those listed in the bin field will be marked as executable in the resulting package archive. The executableFiles field lets you declare additional fields that must have the executable flag (+x) set even if they aren't directly accessible through the bin field.
```json
"publishConfig": {
"executableFiles": [
"./dist/shim.js",
]
}
```
+5
View File
@@ -0,0 +1,5 @@
---
"@pnpm/types": minor
---
Add `publishConfig.executableFiles`.
Whitespace-only changes.
@@ -1,5 +1,8 @@
{
"name": "has-bin",
"version": "0.0.0",
"bin": "exec"
"bin": "exec",
"publishConfig": {
"executableFiles": ["./other-exec"]
}
}
@@ -107,11 +107,15 @@ export async function handler (
async function packPkg (destFile: string, filesMap: Record<string, string>, projectDir: string): Promise<void> {
const { manifest } = await readProjectManifest(projectDir, {})
const bins = await binify(manifest as DependencyManifest, projectDir)
const bins = [
...(await binify(manifest as DependencyManifest, projectDir)).map(({ path }) => path),
...(manifest.publishConfig?.executableFiles ?? [])
.map((executableFile) => path.join(projectDir, executableFile)),
]
const mtime = new Date('1985-10-26T08:15:00.000Z')
const pack = tar.pack()
for (const [name, source] of Object.entries(filesMap)) {
const isExecutable = bins.some((bin) => path.relative(bin.path, source) === '')
const isExecutable = bins.some((bin) => path.relative(bin, source) === '')
const mode = isExecutable ? 0o755 : 0o644
if (/^package\/package\.(json|json5|yaml)/.test(name)) {
const publishManifest = await exportableManifest(projectDir, manifest)
@@ -118,6 +118,10 @@ const modeIsExecutable = (mode: number) => (mode & 0o111) === 0o111
const stat = fs.statSync(path.resolve('package/exec'))
expect(modeIsExecutable(stat.mode)).toBeTruthy()
}
{
const stat = fs.statSync(path.resolve('package/other-exec'))
expect(modeIsExecutable(stat.mode)).toBeTruthy()
}
{
const stat = fs.statSync(path.resolve('package/index.js'))
expect(modeIsExecutable(stat.mode)).toBeFalsy()
+5 -1
View File
@@ -164,7 +164,11 @@
"compile": "rimraf lib tsconfig.tsbuildinfo && tsc --build && pnpm run lint -- --fix && rimraf dist bin/nodes && pnpm run bundle && shx cp -r node-gyp-bin dist/node-gyp-bin && shx cp -r node_modules/@pnpm/tabtab/lib/scripts dist/scripts && shx cp -r node_modules/ps-list/vendor dist/vendor && pkg ./dist/pnpm.cjs --out-path=../artifacts/win-x64 --targets=node14-win-x64 && pkg ./dist/pnpm.cjs --out-path=../artifacts/linux-x64 --targets=node14-linux-x64 && pkg ./dist/pnpm.cjs --out-path=../artifacts/macos-x64 --targets=node14-macos-x64"
},
"publishconfig": {
"tag": "next"
"tag": "next",
"executableFiles": [
"./dist/node-gyp-bin/node-gyp",
"./dist/node-gyp-bin/node-gyp.cmd"
]
},
"funding": "https://opencollective.com/pnpm"
}
+1
View File
@@ -48,6 +48,7 @@ export interface PeerDependenciesMeta {
export interface PublishConfig extends Record<string, unknown> {
directory?: string
executableFiles?: string[]
}
interface BaseManifest {