diff --git a/package.json b/package.json index 5f573dc..3d1c100 100644 --- a/package.json +++ b/package.json @@ -25,12 +25,10 @@ "prepublishOnly": "base prepublishOnly", "test": "base test" }, - "resolutions": { - "nuxi": "3.6.5" - }, "dependencies": { "@babel/core": "^7.10.2", "@dword-design/suppress-babel-register-esm-warning": "^1.1.10", + "@nuxt/kit": "^3.7.0", "@rollup/plugin-babel": "^6.0.3", "@vitejs/plugin-vue": "^4.2.3", "@vue/compiler-sfc": "^3.3.4", diff --git a/src/cli.spec.js b/src/cli.spec.js index 1fd984f..3783ce1 100644 --- a/src/cli.spec.js +++ b/src/cli.spec.js @@ -145,6 +145,100 @@ export default tester( await kill(nuxt.pid) } }, + async 'dev NITRO_PORT env variable'() { + await fs.outputFile( + 'pages/index.vue', + endent` + + `, + ) + + const nuxt = execa(resolver.resolve('./cli.js'), ['dev'], { + env: { NITRO_PORT: 4000 }, + }) + try { + await nuxtDevReady(4000) + await this.page.goto('http://localhost:4000') + expect(await this.page.$eval('.foo', div => div.textContent)).toEqual( + 'Hello world', + ) + } finally { + await kill(nuxt.pid) + } + }, + async 'dev NUXT_PORT env variable'() { + await fs.outputFile( + 'pages/index.vue', + endent` + + `, + ) + + const nuxt = execa(resolver.resolve('./cli.js'), ['dev'], { + env: { NUXT_PORT: 4000 }, + }) + try { + await nuxtDevReady(4000) + await this.page.goto('http://localhost:4000') + expect(await this.page.$eval('.foo', div => div.textContent)).toEqual( + 'Hello world', + ) + } finally { + await kill(nuxt.pid) + } + }, + async 'dev PORT env variable'() { + await fs.outputFile( + 'pages/index.vue', + endent` + + `, + ) + + const nuxt = execa(resolver.resolve('./cli.js'), ['dev'], { + env: { PORT: 4000 }, + }) + try { + await nuxtDevReady(4000) + await this.page.goto('http://localhost:4000') + expect(await this.page.$eval('.foo', div => div.textContent)).toEqual( + 'Hello world', + ) + } finally { + await kill(nuxt.pid) + } + }, + async 'dev port config variable'() { + await outputFiles({ + 'nuxt.config.js': endent` + export default { + devServer: { port: 4000 }, + } + `, + 'pages/index.vue': endent` + + `, + }) + + const nuxt = execa(resolver.resolve('./cli.js'), ['dev']) + try { + await nuxtDevReady(4000) + await this.page.goto('http://localhost:4000') + expect(await this.page.$eval('.foo', div => div.textContent)).toEqual( + 'Hello world', + ) + } finally { + await kill(nuxt.pid) + } + }, 'do not transpile vue in node_modules': async () => { await outputFiles({ 'node_modules/foo': { diff --git a/src/index.js b/src/index.js index 8b47257..004b2d6 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,5 @@ import { transform } from '@babel/core' +import { loadNuxtConfig } from '@nuxt/kit' import { babel as rollupPluginBabel } from '@rollup/plugin-babel' import { parseVueRequest } from '@vitejs/plugin-vue' import { parse } from '@vue/compiler-sfc' @@ -6,8 +7,18 @@ import { runCommand } from 'nuxi' import vitePluginBabel from 'vite-plugin-babel' import vueSfcDescriptorToString from 'vue-sfc-descriptor-to-string' -export default (command, args) => - runCommand(command, args, { +export default async (command, args) => { + command = command === 'dev' ? '_dev' : command + if (command === '_dev') { + const nuxtConfig = await loadNuxtConfig() + process.env._PORT = + process.env.NUXT_PORT || + process.env.NITRO_PORT || + process.env.PORT || + nuxtConfig.devServer.port.toString() + } + + return runCommand(command, args, { overrides: { nitro: { rollupConfig: { @@ -51,3 +62,4 @@ export default (command, args) => }, }, }) +} diff --git a/yarn.lock b/yarn.lock index fcf1a65..f89df07 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2211,7 +2211,7 @@ resolved "https://registry.yarnpkg.com/@nuxt/devalue/-/devalue-2.0.2.tgz#5749f04df13bda4c863338d8dabaf370f45ef7c7" integrity sha512-GBzP8zOc7CGWyFQS6dv1lQz8VVpz5C2yRszbXufwG/9zhStTIH50EtD87NmWbTMwXDvZLNg8GIpb1UFdH93JCA== -"@nuxt/kit@3.7.0", "@nuxt/kit@^3.6.5": +"@nuxt/kit@3.7.0", "@nuxt/kit@^3.6.5", "@nuxt/kit@^3.7.0": version "3.7.0" resolved "https://registry.yarnpkg.com/@nuxt/kit/-/kit-3.7.0.tgz#14046349a7b12412e84782525ef802b65624268f" integrity sha512-bsPRb2NTLHRacjyybhhA3pZFIqo2pxB6bcP4FQDuzlGzVTI5PtJzbfNpkmQC7q+LZt8K0pNlxKVGisDvZctk6w== @@ -3151,7 +3151,7 @@ lodash.kebabcase "^4.1.1" svg-tags "^1.0.0" -"@vue/babel-preset-jsx@dword-design/jsx#fork-babel-preset-jsx": +"@vue/babel-preset-jsx@github:dword-design/jsx#fork-babel-preset-jsx": version "1.1.2" resolved "https://codeload.github.com/dword-design/jsx/tar.gz/a73cb9961541a60a66b1b99a69a32e00bc66d336" dependencies: @@ -6801,9 +6801,9 @@ formdata-polyfill@^4.0.10: fetch-blob "^3.1.2" fraction.js@^4.2.0: - version "4.3.1" - resolved "https://registry.yarnpkg.com/fraction.js/-/fraction.js-4.3.1.tgz#828c46dce1c8ad270e1c4170b3d06a2761e997d3" - integrity sha512-nx0cki48JBA6ThPeUpeKCNpdhEl/9bRS+dAEYnRUod+Z1jhFfC3K/mBLorZZntqHM+GTH3/dkkpfoT3QITYe7g== + version "4.3.2" + resolved "https://registry.yarnpkg.com/fraction.js/-/fraction.js-4.3.2.tgz#ea144a08ed23a284bf9067153075f212771a92d9" + integrity sha512-9VLF466MqX1OUP7/d9r7/Vsvu6Hpp+taXBLmiR5x6mEYfT0BDkGVBt5TyA1aDu1WzIE1sF8F66evOFaz7iAEGQ== fragment-cache@^0.2.1: version "0.2.1" @@ -6892,7 +6892,7 @@ fs.realpath@^1.0.0: resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw== -fsevents@^2.1.2, fsevents@^2.3.2, fsevents@~2.3.2: +fsevents@^2.1.2, fsevents@^2.3.2, fsevents@~2.3.2, fsevents@~2.3.3: version "2.3.3" resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.3.tgz#cac6407785d03675a2a5e1a5305c697b347d90d6" integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw== @@ -8433,14 +8433,13 @@ istanbul-reports@^3.0.2, istanbul-reports@^3.1.6: istanbul-lib-report "^3.0.0" iterator.prototype@^1.1.0: - version "1.1.0" - resolved "https://registry.yarnpkg.com/iterator.prototype/-/iterator.prototype-1.1.0.tgz#690c88b043d821f783843aaf725d7ac3b62e3b46" - integrity sha512-rjuhAk1AJ1fssphHD0IFV6TWL40CwRZ53FrztKx43yk2v6rguBYsY4Bj1VU4HmoMmKwZUlx7mfnhDf9cOp4YTw== + version "1.1.1" + resolved "https://registry.yarnpkg.com/iterator.prototype/-/iterator.prototype-1.1.1.tgz#ab5b790e23ec00658f5974e032a2b05188bd3a5c" + integrity sha512-9E+nePc8C9cnQldmNl6bgpTY6zI4OPRZd97fhJ/iVZ1GifIUDVV5F6x1nEDqpe8KaMEZGT4xgrwKQDxXnjOIZQ== dependencies: - define-properties "^1.1.4" - get-intrinsic "^1.1.3" + define-properties "^1.2.0" + get-intrinsic "^1.2.1" has-symbols "^1.0.3" - has-tostringtag "^1.0.0" reflect.getprototypeof "^1.0.3" jackspeak@^2.0.3: @@ -10480,12 +10479,12 @@ nth-check@^2.0.1, nth-check@^2.1.1: dependencies: boolbase "^1.0.0" -nuxi@3.6.5, nuxi@^3.7.0: - version "3.6.5" - resolved "https://registry.yarnpkg.com/nuxi/-/nuxi-3.6.5.tgz#eceb93e6ad957138776fd544a961b2c05615ccca" - integrity sha512-4XEXYz71UiWWiKC1/cJCzqRSUEImYRmjcvKpSsBKMU58ALYVSx5KIoas5SwLO8tEKO5BS4DAe4u7MYix7hfuHQ== +nuxi@^3.7.0: + version "3.7.3" + resolved "https://registry.yarnpkg.com/nuxi/-/nuxi-3.7.3.tgz#e979601b763cd9c57bec400c265e3879ac907aa4" + integrity sha512-Cg+ygRmhonE6PwAtDeKvKU/0VRqEyzmSSoJYfr0MzwIxQYrBSnLvw0z3UgJl/8MgFKjiZ5Y4wBUEiRsUw8O6uw== optionalDependencies: - fsevents "~2.3.2" + fsevents "~2.3.3" nuxt-dev-ready@^2.0.1: version "2.0.1"