From ce0423501e2179c84f80cc66a5f2c9fb83a22017 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Wed, 18 Sep 2024 09:04:12 -0700 Subject: [PATCH] feat: explicitly include type --- lib/init-package-json.js | 4 ++++ test/basic.js | 2 ++ test/dependencies.js | 1 + test/npm-defaults.js | 1 + 4 files changed, 8 insertions(+) diff --git a/lib/init-package-json.js b/lib/init-package-json.js index 51cbd21..001a721 100644 --- a/lib/init-package-json.js +++ b/lib/init-package-json.js @@ -100,6 +100,10 @@ async function init (dir, delete pkg.content.repository } + if (!pkg.content.type) { + pkg.content.type = 'commonjs' + } + // readJson filters out empty descriptions, but init-package-json // traditionally leaves them alone if (!pkg.content.description) { diff --git a/test/basic.js b/test/basic.js index 166ed34..7b8c9d0 100644 --- a/test/basic.js +++ b/test/basic.js @@ -26,6 +26,7 @@ t.test('the basics', async (t) => { main: 'main.js', config: { foo: 'bar' }, package: {}, + type: 'commonjs', }) }) @@ -47,6 +48,7 @@ t.test('no config', async (t) => { main: 'main.js', config: {}, package: {}, + type: 'commonjs', }) }) diff --git a/test/dependencies.js b/test/dependencies.js index 897b627..0d2860c 100644 --- a/test/dependencies.js +++ b/test/dependencies.js @@ -42,6 +42,7 @@ t.test('read in dependencies and dev deps', async (t) => { main: 'index.js', keywords: [], license: 'ISC', + type: 'commonjs', dependencies: { tap: '*', }, diff --git a/test/npm-defaults.js b/test/npm-defaults.js index 27f9acd..172b728 100644 --- a/test/npm-defaults.js +++ b/test/npm-defaults.js @@ -101,6 +101,7 @@ const EXPECTED = { keywords: [], author: 'npmbot (http://npm.im/)', license: 'WTFPL', + type: 'commonjs', } t.test('npm configuration values pulled from environment', async t => {