From cf6595e4c15551f61b11651a0f968c35ef5b8602 Mon Sep 17 00:00:00 2001 From: Matthias Giger Date: Sun, 11 Feb 2024 18:53:44 +0100 Subject: [PATCH] fix(package): use Bun if available and update workflow release-npm --- .github/workflows/push.yml | 11 +++++------ .gitignore | 1 + README.md | 2 ++ package.json | 21 ++++++++++++--------- test/install.test.js | 4 ++-- test/template.test.js | 12 ++++++------ utility/install-dependencies.js | 6 +++++- 7 files changed, 33 insertions(+), 24 deletions(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index ed57c44..b413629 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -11,12 +11,11 @@ jobs: id-token: write contents: write steps: - - uses: actions/checkout@v3 - - run: npm install - - name: 🧪 Test - run: npm test - - run: npm install -g npm@latest + - uses: actions/checkout@v4 + - uses: oven-sh/setup-bun@v1 + - run: bun install + - run: bun run test - name: 📢 Release - uses: tobua/release-npm-action@v2 + uses: tobua/release-npm-action@v3 with: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.gitignore b/.gitignore index 4295f79..f147267 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ node_modules package-lock.json +bun.lockb jsconfig.json test/download .create-now-temporary diff --git a/README.md b/README.md index 8aeb315..05b1c9d 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,8 @@ Install template for compatible packages like this: npm init --yes now papua # or the same thing with npx npx --yes create-now papua +# using Bun +bun create now papua ``` `--yes` avoids the prompt by `npm` to install this package. diff --git a/package.json b/package.json index 0e64314..28b753c 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "ejs": "^3.1.9", "find-cache-dir": "^5.0.0", "isbinaryfile": "^5.0.0", - "logua": "^3.0.2", + "logua": "^3.0.3", "node-fetch": "^3.3.2", "prompts": "^2.4.2", "temp-dir": "^3.0.0", @@ -26,19 +26,22 @@ "is-png": "^3.0.1", "jest-fixture": "^4.1.0", "mock-stdin": "^1.0.0", - "padua": "^2.0.7", - "read-chunk": "^4.0.3", - "vitest": "^0.34.6" + "vitest": "^0.34.6", + "padua": "^2.0.9", + "read-chunk": "^4.0.3" }, "type": "module", "sideEffects": true, - "main": "index.js", + "main": "./index.js", "exports": { - "default": "./index.js" + ".": { + "types": "./index.d.ts", + "default": "./index.js" + } }, - "bin": "cli.js", - "source": "index.js", - "types": "index.d.ts", + "bin": "./cli.js", + "source": "./index.js", + "types": "./index.d.ts", "files": [ "utility", "*.js", diff --git a/test/install.test.js b/test/install.test.js index 0878fd8..c448319 100644 --- a/test/install.test.js +++ b/test/install.test.js @@ -11,7 +11,7 @@ test('Dependencies are installed if there are any.', async () => { const templateDirectory = await getTemplateDirectory( undefined, undefined, - join(process.cwd(), 'test/fixture/dependencies') + join(process.cwd(), 'test/fixture/dependencies'), ) const config = getConfig(templateDirectory) writeFiles(destination, {}, templateDirectory) @@ -29,7 +29,7 @@ test('Nothing installed if noInstall option is truthy.', async () => { const templateDirectory = await getTemplateDirectory( undefined, undefined, - join(process.cwd(), 'test/fixture/no-install') + join(process.cwd(), 'test/fixture/no-install'), ) const config = getConfig(templateDirectory) writeFiles(destination, {}, templateDirectory) diff --git a/test/template.test.js b/test/template.test.js index db5a752..4759c76 100644 --- a/test/template.test.js +++ b/test/template.test.js @@ -39,7 +39,7 @@ test('Locates template in main directory.', async () => { let templatePath = await getTemplateDirectory( undefined, undefined, - join(process.cwd(), 'test/fixture/basic') + join(process.cwd(), 'test/fixture/basic'), ) expect(templatePath).toEqual(join(process.cwd(), 'test/fixture/basic')) @@ -48,7 +48,7 @@ test('Locates template in main directory.', async () => { templatePath = await getTemplateDirectory( 'default', undefined, - join(process.cwd(), 'test/fixture/basic') + join(process.cwd(), 'test/fixture/basic'), ) expect(templatePath).toEqual(join(process.cwd(), 'test/fixture/basic')) @@ -66,7 +66,7 @@ test('Recoginizes several templates are available.', async () => { const templatePath = await getTemplateDirectory( undefined, undefined, - join(process.cwd(), 'test/fixture/nested') + join(process.cwd(), 'test/fixture/nested'), ) expect(templatePath).toEqual(join(process.cwd(), 'test/fixture/nested/second')) @@ -79,7 +79,7 @@ test('Fails when given template not available.', async () => { }) expect( - getTemplateDirectory('fourth', undefined, join(process.cwd(), 'test/fixture/nested')) + getTemplateDirectory('fourth', undefined, join(process.cwd(), 'test/fixture/nested')), ).rejects.toEqual(new Error('Exit')) expect(mockProcessExit).toHaveBeenCalledWith(0) @@ -89,7 +89,7 @@ test('Automatically selects first template if only one is available.', async () const templatePath = await getTemplateDirectory( undefined, undefined, - join(process.cwd(), 'test/fixture/single') + join(process.cwd(), 'test/fixture/single'), ) expect(templatePath).toEqual(join(process.cwd(), 'test/fixture/single/first')) @@ -99,7 +99,7 @@ test('Automatically selects default template if no selection provided.', async ( const templatePath = await getTemplateDirectory( undefined, undefined, - join(process.cwd(), 'test/fixture/default') + join(process.cwd(), 'test/fixture/default'), ) expect(templatePath).toEqual(join(process.cwd(), 'test/fixture/default/default')) }) diff --git a/utility/install-dependencies.js b/utility/install-dependencies.js index 6d8709f..cae2160 100644 --- a/utility/install-dependencies.js +++ b/utility/install-dependencies.js @@ -43,7 +43,11 @@ export const installDependencies = (config, destination) => { log('installing dependencies') - execSync('npm install --legacy-peer-deps', { stdio: 'inherit', cwd: destination }) + if (typeof Bun !== 'undefined') { + execSync('bun install', { stdio: 'inherit', cwd: destination }) + } else { + execSync('npm install', { stdio: 'inherit', cwd: destination }) + } log('dependencies installed') }