From 2d0f98fc119e30ebd8c19462e3280ec2762843a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Ba=CC=88chler?= Date: Mon, 17 Nov 2025 10:42:52 +0100 Subject: [PATCH 1/2] fix: Fix how cwd is resolved --- create/index.js | 24 +++++++++++++++++------- tests/generator.test.mjs | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/create/index.js b/create/index.js index dc60c4b..5713a21 100755 --- a/create/index.js +++ b/create/index.js @@ -6,8 +6,8 @@ import path from 'node:path'; import { fileURLToPath } from 'node:url'; const __filename = fileURLToPath(import.meta.url); -const cwd = path.dirname(path.dirname(__filename)); -const templateDir = path.join(cwd, 'template'); +const packageRoot = path.dirname(path.dirname(__filename)); +const templateDir = path.join(packageRoot, 'template'); function targetFromArgv() { const argv = process.argv.slice(2); @@ -29,13 +29,23 @@ function normalizeOptions(input = {}) { opts.project || targetFromArgv(); + const resolvedCwd = + typeof opts.cwd === 'string' && opts.cwd.length > 0 + ? path.resolve(process.cwd(), opts.cwd) + : process.cwd(); + + const resolvedTargetDir = + typeof targetDir === 'string' && targetDir.length > 0 + ? path.resolve(resolvedCwd, targetDir) + : undefined; + return { - cwd, - templateDir: templateDir, // always use the built-in template - targetDir, + ...opts, + targetDir: resolvedTargetDir, debug: !!opts.debug, install: opts.install ?? true, - ...opts + cwd: resolvedCwd, + templateDir // always use the built-in template }; } @@ -56,4 +66,4 @@ async function main(...args) { await createMain(opts); } -main().catch(console.error.bind(console)); \ No newline at end of file +main().catch(console.error.bind(console)); diff --git a/tests/generator.test.mjs b/tests/generator.test.mjs index 62c0f3a..8c9a041 100644 --- a/tests/generator.test.mjs +++ b/tests/generator.test.mjs @@ -25,16 +25,18 @@ describe('create-tinker-stack generator', () => { 'scaffolds project and passes build checks', async () => { const tempRoot = await mkdtemp(path.join(os.tmpdir(), 'tinker-stack-')); - const projectDir = path.join(tempRoot, 'demo-app'); + const appFolder = 'demo-app'; + const projectDir = path.join(tempRoot, appFolder); try { - await runCommand('node', [CLI_ENTRY, projectDir], { + await runCommand('node', [CLI_ENTRY, appFolder], { env: { ...process.env, CI: '1', SKIP_SETUP: '1', SKIP_FORMAT: '1' - } + }, + cwd: tempRoot }); const packageJson = JSON.parse(await readFile(path.join(projectDir, 'package.json'), 'utf8')); @@ -55,4 +57,30 @@ describe('create-tinker-stack generator', () => { }, 10 * 60 * 1000 ); + + test( + 'scaffolds into the current working directory when no target is provided', + async () => { + const tempRoot = await mkdtemp(path.join(os.tmpdir(), 'tinker-stack-')); + const expectedDir = path.join(tempRoot, 'demo-title'); + + try { + await runCommand('node', [CLI_ENTRY], { + env: { + ...process.env, + CI: '1', + SKIP_SETUP: '1', + SKIP_FORMAT: '1' + }, + cwd: tempRoot + }); + + const packageJson = JSON.parse(await readFile(path.join(expectedDir, 'package.json'), 'utf8')); + expect(packageJson.name).toBe('demo-title'); + } finally { + await rm(tempRoot, { recursive: true, force: true }); + } + }, + 2 * 60 * 1000 + ); }); From 4d8bc777996ceeb9058fed2b6abf9b149d602f89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Ba=CC=88chler?= Date: Mon, 17 Nov 2025 10:43:40 +0100 Subject: [PATCH 2/2] docs: Add instructions for how to test the repo locally before publishing --- .gitignore | 1 + README.md | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/.gitignore b/.gitignore index afda6bb..b2df8b8 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,7 @@ dist /public/build tsconfig.tsbuildinfo data-mocks/ +*.tgz # Debug npm-debug.log* diff --git a/README.md b/README.md index b482b3f..856f863 100644 --- a/README.md +++ b/README.md @@ -50,3 +50,11 @@ To get started, run the following command: ```bash npm create tinker-stack ``` + +### Local testing + +To verify the generator before publishing: + +1. Run `npm pack` in this repository to produce a tarball (for example `create-tinker-stack-0.2.2.tgz`). +2. In a temporary directory, execute `npx --yes create-tinker-stack@file:/absolute/path/to/create-tinker-stack-0.2.2.tgz`. + - Replace the path with the absolute path to the tarball from step 1 (npm `create` does not currently support `file:` specifiers).