-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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: copy LICENSE file from monorepo root on pack #6366
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
releases: | ||
"@yarnpkg/cli": minor | ||
"@yarnpkg/plugin-pack": major | ||
|
||
declined: | ||
- "@yarnpkg/plugin-compat" | ||
- "@yarnpkg/plugin-constraints" | ||
- "@yarnpkg/plugin-dlx" | ||
- "@yarnpkg/plugin-essentials" | ||
- "@yarnpkg/plugin-init" | ||
- "@yarnpkg/plugin-interactive-tools" | ||
- "@yarnpkg/plugin-nm" | ||
- "@yarnpkg/plugin-npm" | ||
- "@yarnpkg/plugin-npm-cli" | ||
- "@yarnpkg/plugin-patch" | ||
- "@yarnpkg/plugin-pnp" | ||
- "@yarnpkg/plugin-pnpm" | ||
- "@yarnpkg/plugin-stage" | ||
- "@yarnpkg/plugin-typescript" | ||
- "@yarnpkg/plugin-version" | ||
- "@yarnpkg/plugin-workspace-tools" | ||
- "@yarnpkg/builder" | ||
- "@yarnpkg/core" | ||
- "@yarnpkg/doctor" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ import {createGzip} fr | |
|
||
import {Hooks} from './'; | ||
|
||
const LICENSE_PATTERN = /licen[cs]e(\.[a-zA-Z0-9]+)?/i; | ||
|
||
const NEVER_IGNORE = [ | ||
`/package.json`, | ||
|
||
|
@@ -67,9 +69,10 @@ export async function prepareForPack(workspace: Workspace, {report}: {report: Re | |
} | ||
} | ||
|
||
export async function genPackStream(workspace: Workspace, files?: Array<PortablePath>) { | ||
if (typeof files === `undefined`) | ||
files = await genPackList(workspace); | ||
export async function genPackStream(workspace: Workspace, files?: Array<PortablePath | {file: PortablePath, source: PortablePath}>) { | ||
const normalizedFiles = files?.map(file => typeof file === `string` | ||
? {file, source: ppath.resolve(workspace.cwd, file)} | ||
: file) ?? await genPackList(workspace); | ||
|
||
const executableFiles = new Set<PortablePath>(); | ||
for (const value of workspace.manifest.publishConfig?.executableFiles ?? new Set()) | ||
|
@@ -80,10 +83,9 @@ export async function genPackStream(workspace: Workspace, files?: Array<Portable | |
const pack = tar.pack(); | ||
|
||
process.nextTick(async () => { | ||
for (const fileRequest of files!) { | ||
for (const {file: fileRequest, source} of normalizedFiles!) { | ||
const file = ppath.normalize(fileRequest); | ||
|
||
const source = ppath.resolve(workspace.cwd, file); | ||
const dest = ppath.join(`package`, file); | ||
|
||
const stat = await xfs.lstatPromise(source); | ||
|
@@ -239,11 +241,34 @@ export async function genPackList(workspace: Workspace) { | |
} | ||
} | ||
|
||
return await walk(workspace.cwd, { | ||
const paths = await walk(workspace.cwd, { | ||
hasExplicitFileList, | ||
globalList, | ||
ignoreList, | ||
}); | ||
|
||
const files = paths.map(path => ({file: path, source: ppath.resolve(workspace.cwd, path)})); | ||
|
||
if (workspace.cwd !== project.cwd) { | ||
const workspaceHasLicense = paths.some(path => path.match(LICENSE_PATTERN)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hardcoding something about LICENSE files in this function feels a little too specific. Perhaps instead the files set via the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey @arcanis the regex is case-insensitive. Also, in this case, it's a little hard to reduce specificity because what we are doing is so specific :p. Would love any suggestion for alternatives. |
||
|
||
if (!workspaceHasLicense) { | ||
const projectDir = await xfs.readdirPromise(project.cwd); | ||
|
||
const licenses = await Promise.all(projectDir | ||
.filter(path => path.match(LICENSE_PATTERN)) | ||
.map(async path => [path, await xfs.lstatPromise(ppath.join(project.cwd, path))] as const)) | ||
.then(result => result | ||
.filter(([_, stat]) => stat.isFile()) | ||
.map(([file]) => file)); | ||
|
||
for (const file of licenses) { | ||
files.push({file, source: ppath.join(project.cwd, file)}); | ||
} | ||
} | ||
} | ||
|
||
return files; | ||
} | ||
|
||
async function walk(initialCwd: PortablePath, {hasExplicitFileList, globalList, ignoreList}: {hasExplicitFileList: boolean, globalList: IgnoreList, ignoreList: IgnoreList}) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest to make
source
astring
parameter (and to read the content of the license file outside of thegenPackStream
function); this way it gives us a way to generate files within the archive that don't necessarily exist on disk (for example if we wanted to generate the LICENSE file from the SPDX code).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe source is already is a
string
becausePortablePath
is in fact astring
. I'm not too aware of the differences between the 2 though.Also because I'm not too familiar with how gzip and tar works. Can give me further guidance on where the inclusion of LICENSE files should happen instead? Are you suggesting that
genPackStream
should also accept something like{ file: PortablePath, content: string | Buffer }
?