Skip to content

Commit

Permalink
feat(pack): support .gitignore match
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Cui <[email protected]>
  • Loading branch information
BlackHole1 committed Jan 14, 2025
1 parent fd24553 commit 3c262e0
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"dependencies": {
"commander": "^12.1.0",
"execa": "^9.5.0",
"fast-glob": "^3.3.2",
"globby": "^14.0.2",
"tar": "^7.4.3",
"yaml": "^2.6.0"
}
Expand Down
43 changes: 40 additions & 3 deletions pnpm-lock.yaml

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

14 changes: 7 additions & 7 deletions src/cmd/install.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from "node:path";
import fg from "fast-glob";
import { globby } from "globby";
import { beforeEach, describe, expect, it } from "vitest";
import { fixture } from "../../tests/helper/fs";
import { Registry } from "../../tests/helper/registry";
Expand Down Expand Up @@ -39,7 +39,7 @@ describe.sequential("install file", () => {

expect(await exists(path.join(ctx.workdir, folderName, ooPackageName))).toBe(true);

const fileList = await fg.glob("**/*", {
const fileList = await globby("**", {
cwd: path.join(ctx.workdir, folderName),
onlyFiles: true,
absolute: false,
Expand Down Expand Up @@ -89,7 +89,7 @@ describe.sequential("install file", () => {

expect(await exists(path.join(ctx.workdir, folderName, ooPackageName))).toBe(true);

const fileList = await fg.glob("**/*", {
const fileList = await globby("**", {
cwd: path.join(ctx.workdir, folderName),
onlyFiles: true,
absolute: false,
Expand Down Expand Up @@ -202,7 +202,7 @@ describe.sequential("install all", () => {
},
});

const fileList = await fg.glob(`**/${ooPackageName}`, {
const fileList = await globby(`**/${ooPackageName}`, {
cwd: distDir,
onlyFiles: true,
absolute: false,
Expand Down Expand Up @@ -303,7 +303,7 @@ describe.sequential("install deps", () => {
d: "0.0.1",
});

const fileList = await fg.glob(`**/${ooPackageName}`, {
const fileList = await globby(`**/${ooPackageName}`, {
cwd: distDir,
onlyFiles: true,
absolute: false,
Expand Down Expand Up @@ -383,7 +383,7 @@ describe.sequential("install deps", () => {
b: "0.0.1",
});

const fileList = await fg.glob(`**/${ooPackageName}`, {
const fileList = await globby(`**/${ooPackageName}`, {
cwd: distDir,
onlyFiles: true,
absolute: false,
Expand Down Expand Up @@ -445,7 +445,7 @@ describe.sequential("install deps", () => {
},
});

const fileList = await fg.glob(`**/${ooPackageName}`, {
const fileList = await globby(`**/${ooPackageName}`, {
cwd: distDir,
onlyFiles: true,
absolute: false,
Expand Down
17 changes: 15 additions & 2 deletions src/cmd/pack.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from "node:path";
import { execa } from "execa";
import { globby } from "globby";
import { copyDir, remove, tempDir, writeFile } from "../utils/fs";
import { env } from "../utils/misc";
import { generatePackageJson } from "../utils/npm";
Expand All @@ -16,10 +17,22 @@ export async function prePack(p: string, ignore: string[]) {

const workdir = await tempDir();

const files = await globby("**", {
cwd: p,
dot: true,
onlyFiles: false,
gitignore: true,
ignore,
absolute: true,
});

await Promise.all([
copyDir(p, path.join(workdir, "package"), (source, _) => {
const relative = path.relative(p, source).split(path.sep);
return !ignore.some(i => relative.includes(i));
if (source === p) {
return true;
}

return files.includes(source);
}),
writeFile(path.join(workdir, "package.json"), packageJson),
]);
Expand Down
4 changes: 2 additions & 2 deletions src/utils/npm.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Deps, OOPackageSchema } from "../types";
import path from "node:path";
import fg from "fast-glob";
import { globby } from "globby";
import YAML from "yaml";
import { ooPackageName } from "../const";
import { exists, readFile, writeFile } from "./fs";
Expand Down Expand Up @@ -120,7 +120,7 @@ export async function createNpmrc(dir: string, registry: string, token: string)
}

export async function transformNodeModules(dir: string) {
const result = await fg("node_modules/**/package/package.oo.yaml", {
const result = await globby("node_modules/**/package/package.oo.yaml", {
onlyFiles: true,
cwd: dir,
dot: false,
Expand Down

0 comments on commit 3c262e0

Please sign in to comment.