Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,33 @@ When a local template contains `pnpm-workspace.yaml`, the file is only copied
if the project is created with pnpm. Templates loaded from third-party npm
packages are copied without this filtering.

The toolkit automatically passes the resolved `skipFiles` list to custom
`extraTools` actions. When an action uses `copyFolder` to copy a local tool
template, forward the received list so the same package-manager filtering is
applied:

```ts
import { copyFolder, create } from '@rstackjs/create-toolkit';

create({
extraTools: [
{
value: 'storybook',
label: 'Storybook',
action: ({ distFolder, skipFiles }) => {
copyFolder({
from: storybookTemplate,
to: distFolder,
skipFiles,
isMergePackageJson: true,
});
},
},
],
// ...other options
});
```

### Git Initialization

By default, the toolkit initializes a Git repository after creating the
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ type ExtraTool = {
action?: (context: {
templateName: string;
distFolder: string;
skipFiles: string[];
addAgentsMdSearchDirs: (dir: string) => void;
}) => unknown;
/**
Expand Down Expand Up @@ -932,6 +933,7 @@ export async function create({
await matchedTool.action({
templateName,
distFolder,
skipFiles: [...localSkipFiles],
addAgentsMdSearchDirs: (dir: string) =>
agentsMdSearchDirs.push(dir),
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
allowBuilds:
esbuild: true
60 changes: 59 additions & 1 deletion test/package-manager-files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { beforeEach, expect, rs, test } from 'rstack/test';
import { create } from '../src';
import { copyFolder, create } from '../src';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const fixturesDir = path.join(__dirname, 'fixtures', 'package-manager-files');
const testDir = path.join(fixturesDir, 'test-temp-output');
const extraToolDir = path.join(fixturesDir, 'template-storybook');

beforeEach(() => {
rs.unstubAllEnvs();
Expand Down Expand Up @@ -36,6 +37,41 @@ async function createProject(projectDir: string) {
});
}

async function createProjectWithExtraTool(projectDir: string) {
await create({
name: 'test',
root: fixturesDir,
templates: ['vanilla'],
getTemplateName: async () => 'vanilla',
git: false,
builtinTools: [],
extraTools: [
{
value: 'storybook',
label: 'Storybook',
action: ({ distFolder, skipFiles }) => {
copyFolder({
from: extraToolDir,
to: distFolder,
skipFiles,
isMergePackageJson: true,
});
},
},
],
argv: [
'node',
'test',
'--dir',
projectDir,
'--template',
'vanilla',
'--tools',
'storybook',
],
});
}

test('should copy pnpm-workspace.yaml for pnpm', async () => {
const projectDir = path.join(testDir, 'pnpm');
rs.stubEnv('npm_config_user_agent', 'pnpm/11.20.0');
Expand All @@ -57,3 +93,25 @@ test('should skip pnpm-workspace.yaml for other package managers', async () => {
false,
);
});

test('should copy pnpm-workspace.yaml from an extra tool for pnpm', async () => {
const projectDir = path.join(testDir, 'extra-tool-pnpm');
rs.stubEnv('npm_config_user_agent', 'pnpm/11.20.0');

await createProjectWithExtraTool(projectDir);

expect(
fs.readFileSync(path.join(projectDir, 'pnpm-workspace.yaml'), 'utf8'),
).toBe('allowBuilds:\n esbuild: true\n');
});

test('should skip pnpm-workspace.yaml from an extra tool for npm', async () => {
const projectDir = path.join(testDir, 'extra-tool-npm');
rs.stubEnv('npm_config_user_agent', 'npm/11.0.0');

await createProjectWithExtraTool(projectDir);

expect(fs.existsSync(path.join(projectDir, 'pnpm-workspace.yaml'))).toBe(
false,
);
});