-
Notifications
You must be signed in to change notification settings - Fork 916
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
support custom web modules dir #483
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -316,6 +316,7 @@ function handleLegacyProxyScripts(config: any) { | |
|
||
type RawScripts = Record<string, string>; | ||
function normalizeScripts(cwd: string, scripts: RawScripts): BuildScript[] { | ||
const dependenciesLoc = process.env.NODE_ENV === 'production' ? BUILD_DEPENDENCIES_DIR : DEV_DEPENDENCIES_DIR; | ||
const processedScripts: BuildScript[] = []; | ||
if (Object.keys(scripts).filter((k) => k.startsWith('bundle:')).length > 1) { | ||
handleConfigError(`scripts can only contain 1 script of type "bundle:".`); | ||
|
@@ -354,8 +355,15 @@ function normalizeScripts(cwd: string, scripts: RawScripts): BuildScript[] { | |
`scripts[${scriptId}]: "--to ${to}" must be a URL path, and start with a "/"`, | ||
); | ||
} | ||
const dirDisk = cmdArr[0]; | ||
let dirDisk = cmdArr[0]; | ||
const dirUrl = to || `/${cmdArr[0]}`; | ||
|
||
// mount:web_modules is a special case script where the fromDisk | ||
// arg is harcoded to match the internal dependency dir | ||
if (scriptId === 'mount:web_modules') { | ||
dirDisk = dependenciesLoc; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I know the code that was here before was a little confusing (at least to me), and you changed as little as possible. But with this addition do you think you could add a comment or two to explain what this section is doing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes! Hadn't seen too many existing comments in the |
||
|
||
newScriptConfig.args = { | ||
fromDisk: path.posix.normalize(dirDisk + '/'), | ||
toUrl: path.posix.normalize(dirUrl + '/'), | ||
|
@@ -379,15 +387,13 @@ function normalizeScripts(cwd: string, scripts: RawScripts): BuildScript[] { | |
} | ||
|
||
if (!scripts['mount:web_modules']) { | ||
const fromDisk = | ||
process.env.NODE_ENV === 'production' ? BUILD_DEPENDENCIES_DIR : DEV_DEPENDENCIES_DIR; | ||
processedScripts.push({ | ||
id: 'mount:web_modules', | ||
type: 'mount', | ||
match: ['web_modules'], | ||
cmd: `mount $WEB_MODULES --to /web_modules`, | ||
args: { | ||
fromDisk, | ||
fromDisk: dependenciesLoc, | ||
toUrl: '/web_modules', | ||
}, | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const execa = require('execa'); | ||
|
||
it('custom web_modules folder', () => { | ||
execa.sync('npm', ['run', 'TEST'], { | ||
cwd: __dirname, | ||
// override NODE_ENV=test from jest, otherwise snowpack will assume | ||
// development mode and try to copy from DEV_DEPENDENCIES_DIR | ||
env: { NODE_ENV: 'production' } | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch! And good comment here. |
||
|
||
// should write modules to the custom folder on disk | ||
expect(fs.existsSync(path.join(__dirname, 'build', 'my_modules', 'array-flatten.js'))).toBe(true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! 👍 |
||
|
||
// should rewrite path for web_modules imports | ||
const outputJS = fs.readFileSync(path.resolve(__dirname, 'build', '_dist_', 'index.js'), 'utf8'); | ||
expect(outputJS).toContain('/my_modules/array-flatten.js'); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@FredKSchott What do you think about doing this instead?
That would make the Script Variables section of the docs more accurate and technically it'd be a little bit more flexible. Not sure that anyone needs/wants that flexibility though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, I think that's a good idea. Feel free to tackle in a future PR