Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add buildProject JS API, clean up config API #1862

Merged
merged 2 commits into from
Dec 9, 2020
Merged

add buildProject JS API, clean up config API #1862

merged 2 commits into from
Dec 9, 2020

Conversation

FredKSchott
Copy link
Owner

@FredKSchott FredKSchott commented Dec 8, 2020

/cc @drwpow, @Rich-Harris

Changes

  • New buildProject() JS API.
    • this builds the entire project. If you need per-file builds, continue to use the dev server (startDevServer).
    • this allows for better programatic usage + helps us improve testing via the JS API. (/cc @drwpow)
  • Cleans up config API (no breaking changes now, but loadAndValidateConfig() will be removed in v3.0 since it confuses usage with the much simpler createConfiguration() method).

Testing

  • Covered by existing tests

Docs

  • TODO

@vercel
Copy link

vercel bot commented Dec 8, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/pikapkg/snowpack/5n3txqr62
✅ Preview: https://snowpack-git-wip-js-api.pikapkg.vercel.app

@FredKSchott
Copy link
Owner Author

@drwpow once we start resolving by the project root (config file directory, instead of cwd) our tests can look something like this:

const config = snowpack.createConfiguration({root: TEST_DIR});
const {result} = await snowpack.buildProject({config});
expect(result['/path/to/output.js'].contents).toEqual(TEST_RESULT);

And then, we can look into creating a fixtures system for our most common tests (keeping the current full directory support for any too-complicated tests that need a full directory to express). Some examples:

// Example 1: Simplest form
// /test/build/fixtures/relative-import.json
{
  input: "import imgUrl from './test.png';",
  output: "import imgUrl from './test.png.proxy.js';", 
}

// Example 2: multi-file
// /test/build/fixtures/lazy-import.json
{
  input: {
    "file1.ts": "import './file2';",
    "file2.ts": "export const test: boolean = true;"
  }
  output: {
    "file1.js": "import './file2.js';",
    "file2.js": "export const test = true;"
  }
}

// Example 3: with simple config
// /test/build/fixtures/mount-simple.json
{
  config: {mount: {"src": "_dist_"}},
  input: {
    "src/file1.ts": "export const test: boolean = true;"
  }
  output: {
    "_dist_/file1.js": "export const test = true;"
  }

@Rich-Harris
Copy link
Contributor

This is great news, since I'm currently trying to pass a --mount..foo/bar=/baz option (as in, .foo/bar should be mounted as /baz) but I can't work out how to get yargs parser to treat that as

mount: { '.foo/bar': '/baz' }

as opposed to

mount: { '': { 'foo/bar': '/baz' } }

whereas it will be trivial with the JS API.

@FredKSchott FredKSchott merged commit 8d5290f into main Dec 9, 2020
@FredKSchott FredKSchott deleted the wip-js-api branch December 9, 2020 04:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants