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 buildOptions.metaDir option #456

Merged
merged 1 commit into from
Jun 10, 2020
Merged

Add buildOptions.metaDir option #456

merged 1 commit into from
Jun 10, 2020

Conversation

drwpow
Copy link
Collaborator

@drwpow drwpow commented Jun 10, 2020

Reason for Change

Addresses #442 with a new config option (and a new buildOptions namespace):

module.exports = {
  buildOptions: {
    metaDir: 'static/snowpack'
  }
}

Feedback

The option name

I’m 🍌 (unopinionated) on the metaDir name itself. I wanted something more specific than “meta,” or “metadata“ and didn’t know what else to call it.

But buildOptions felt like a logical namespace alongside installOptions and devOptions. I simply included it here, and not devOptions, because it does exist mostly at the build command.

Test additions

This adds a new /test/build folder to test snowpack build. I felt that the existing integration tests that try and look for the same expected-install and expected-output.txt structure might be weird and preserve.

@drwpow drwpow requested a review from FredKSchott June 10, 2020 01:33
"test": "jest test/integration/runner.js --test-timeout=15000 --testMatch \"**/test/**/*.[jt]s?(x)\" -i",
"test": "npm run test:integration && npm run test:build",
"test:build": "jest test/build",
"test:integration": "jest test/integration/runner.js --test-timeout=15000 --testMatch \"**/test/**/*.[jt]s?(x)\" -i",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

❓Is this a good change to allow for more dev & build tests in the future?

hasHmr = false,
) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I personally like converting function params to an option whenever it gets > 4, especially when some are optional. I never can remember the ordering 😅

code,
hasHmr = false,
buildOptions,
}: {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Another example of ordered params -> option

Copy link
Owner

Choose a reason for hiding this comment

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

Yea with just JS I'd 100% agree, with TS types I'm ambivalent but overall I'm 👍 if it helps others

@@ -113,6 +113,9 @@ export interface SnowpackConfig {
dedupe?: string[];
};
};
buildOptions: {
metadataDir: string;
};
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The core code change 👆. Everything else is just implementation.

// remove leading/trailing slashes
config.buildOptions.metadataDir = config.buildOptions.metadataDir
.replace(/^(\/|\\)/g, '') // replace leading slash
.replace(/(\/|\\)$/g, ''); // replace trailing slash
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also see here: I figured a lot of people would try /static/snowpack/ as the option, and wanted to handle that here.

@drwpow drwpow force-pushed the drwpow/metadata-folder branch 3 times, most recently from 25036ca to 60bd5b2 Compare June 10, 2020 01:43
Copy link
Owner

@FredKSchott FredKSchott left a comment

Choose a reason for hiding this comment

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

LGTM, left a couple of small comments but nothing major, feel free to merge when ready!

@@ -50,6 +50,7 @@ $ snowpack dev --no-bundle
"scripts": { /* ... */ },
"installOptions": { /* ... */ },
"devOptions": { /* ... */ },
"buildOptions": { /* ... */ },
Copy link
Owner

Choose a reason for hiding this comment

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

+1, plenty of things in devOptions should really be moved to buildOptions. It would be a good follow-up to this PR to migrate the relevant ones over from devOptions -> buildOptions, if we could continue to support the legacy devOptions usage in our normalizeConfig() function.

docs/05-configuration.md Outdated Show resolved Hide resolved
docs/05-configuration.md Outdated Show resolved Hide resolved
url: proxiedUrl,
code: proxiedCode,
ext: proxiedExt,
buildOptions: config.buildOptions,
Copy link
Owner

Choose a reason for hiding this comment

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

I have a slight preference for passing around the full config option whenever we need access to a full slice of config, instead of destructuring different parts of it. Especially in TypeScript, it's less mental overhead to only keep track of a single config type.

Would also be +1 with just passing the single metaDir string as an argument instead of any config objects.

Will leave it up to you how to resolve, if you have strong feels either way.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah passing the full config makes sense. I did think about the individual metaDir string, but I wanted to keep the mental mapping to where that comes from, as well as reduce noise if something else was needed from config. To that end the full config makes more sense!

const path = require('path');
const execa = require('execa');

it('buildOptions.metadataDir', () => {
Copy link
Owner

Choose a reason for hiding this comment

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

fine for our first test, but our 2nd/3rd test should move this into a runner similar to test/integrations so that we can standardize the test structure.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah totally agree. I just didn’t have a good feel for what that runner should be; hopefully a few more tests in this direction will make that clearer.

@drwpow drwpow force-pushed the drwpow/metadata-folder branch 3 times, most recently from 8ac9215 to d50c9d6 Compare June 10, 2020 15:55
@drwpow drwpow force-pushed the drwpow/metadata-folder branch from d50c9d6 to 39e5252 Compare June 10, 2020 15:59
@drwpow drwpow changed the title Add buildOptions.metadataDir option Add buildOptions.metaDir option Jun 10, 2020
@drwpow drwpow merged commit b76ce6e into master Jun 10, 2020
@drwpow drwpow deleted the drwpow/metadata-folder branch June 10, 2020 16:08
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