Skip to content

feat: improve programatic usage#6868

Merged
pi0 merged 15 commits intodevfrom
feat/get-nuxt
Jan 19, 2020
Merged

feat: improve programatic usage#6868
pi0 merged 15 commits intodevfrom
feat/get-nuxt

Conversation

@pi0
Copy link
Copy Markdown
Member

@pi0 pi0 commented Jan 14, 2020

Types of changes

  • Bug fix (a non-breaking change which fixes an issue)
  • New feature (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

UPDATE: See docs

  • Refactor config loading logic into @nuxt/config package and abstract from CLI arguments
  • Expose loadNuxtConfig, loadNuxt, getBuilder, build and getGenerator

Goal: Making programmatic usage better for making custom solutions without the need to worry about loading config, handling breaking changes for class constructors. Also making @nuxt/cli more lightweight only focusing on its own functionality.

Example:

import { loadNuxt } from 'nuxt'

// Load nuxt instances with config loaded from the current directory
const nuxt  = await loadNuxt({ for: 'dev' })

// Specify rootDir (and/or configFile)
const nuxt = await loadNuxt({ rootDir, for: 'start' })

New programmatic usage for using as a middleware: See Example

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly. (PR: feat: loadNuxt and build docs#1811)
  • I have added tests to cover my changes (if not applicable, please state why)
  • All new and existing tests are passing.

@pi0
Copy link
Copy Markdown
Member Author

pi0 commented Jan 14, 2020

(some GH steps failing because of cache issues)

@pi0 pi0 requested review from a team and atinux January 14, 2020 15:31
@codecov-io
Copy link
Copy Markdown

codecov-io commented Jan 14, 2020

Codecov Report

Merging #6868 into dev will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##              dev    #6868   +/-   ##
=======================================
  Coverage   64.46%   64.46%           
=======================================
  Files          82       82           
  Lines        2744     2744           
  Branches      714      714           
=======================================
  Hits         1769     1769           
  Misses        741      741           
  Partials      234      234
Flag Coverage Δ
#unit 64.46% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dbfa857...98f3b0d. Read the comment docs.

kevinmarrec
kevinmarrec previously approved these changes Jan 14, 2020
@kevinmarrec
Copy link
Copy Markdown
Contributor

kevinmarrec commented Jan 14, 2020

@pi0 What's wrong with node-sass audit ? Doesn't sound related to cache

EDIT: Unless it takes into account vulnerability in some bugged node_modules cache
EDIT2: https://www.npmjs.com/advisories/961 Sounds like the advisory has been published yesterday

clarkdo
clarkdo previously approved these changes Jan 14, 2020
Copy link
Copy Markdown
Member

@clarkdo clarkdo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pi0 @kevinmarrec The github action failure is because of a new found DoS vulnerability in all versions of node-sass which doesn't have a patch yet.
https://www.npmjs.com/advisories/961

@@ -1,3 +1,12 @@
import { loadNuxtConfig } from '@nuxt/config'
import Nuxt from './nuxt'
Copy link
Copy Markdown
Member

@clarkdo clarkdo Jan 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have export { default as Nuxt } from './nuxt' below, now it can be :

export Nuxt

Same for export { loadNuxtConfig } from '@nuxt/config'

Copy link
Copy Markdown
Member Author

@pi0 pi0 Jan 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking this way ensure less breaking changes and the fact that we don't export something else by accident. Also fewer characters :)

@pi0 pi0 dismissed stale reviews from clarkdo and kevinmarrec via fd780ce January 14, 2020 22:01
@pi0 pi0 changed the title feat: expose getNuxt and loadNuxtConfig utilities feat: improve programatic usage Jan 15, 2020
@@ -1 +1,10 @@
import Builder from './builder'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be export default Builder ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @pi0

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way of exporting classes can be improved in another PR :)

@clarkdo
Copy link
Copy Markdown
Member

clarkdo commented Jan 17, 2020

Is this a breaking change?

If not, we’ll have 2 different programmatic ways, are we planning to remove old way in next release?

@pi0
Copy link
Copy Markdown
Member Author

pi0 commented Jan 17, 2020

@clarkdo No, this PR doesn't break the current type of usage but adding new recommended method of getting nuxt instance.

@pi0 pi0 merged commit 2707bdb into dev Jan 19, 2020
@pi0 pi0 deleted the feat/get-nuxt branch January 19, 2020 08:36
This was referenced Feb 25, 2020
@crutch12
Copy link
Copy Markdown
Contributor

Hi, @pi0
Suddenly found out that publicRuntimeConfig/privateRuntimeConfig doesn't work with legacy programatic usage:

server.js

const { Nuxt, Builder } = require('nuxt');
const nuxt = new Nuxt(config);
await nuxt.ready();

nuxt.config.js

export default {
    publicRuntimeConfig: ($env) => {
      return {
        NODE_ENV: $env.NODE_ENV,
        wtf: 'WTF',
      };
    },
}

The resulting script

<script>window.__NUXT__={config:{},staticAssetsBase:void 0}</script>

instead of

<script>window.__NUXT__={config:{NODE_ENV:"development",wtf:"WTF"},staticAssetsBase:void 0}</script>

It would be great to deprecate legacy syntax or add support for runtimeConfig

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants