Skip to content

Commit

Permalink
Set resolve.symlinks based on node option
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeasday committed Aug 1, 2022
1 parent d3aa364 commit 7aaa253
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ export default async (
const shouldCheckTs = typescriptOptions.check && !typescriptOptions.skipBabel;
const tsCheckOptions = typescriptOptions.checkOptions || {};

const { NODE_OPTIONS, NODE_PRESERVE_SYMLINKS } = process.env;
const isPreservingSymlinks =
!!NODE_PRESERVE_SYMLINKS || NODE_OPTIONS?.includes('--preserve-symlinks');

return {
name: 'preview',
mode: isProd ? 'production' : 'development',
Expand Down Expand Up @@ -269,6 +273,9 @@ export default async (
assert: require.resolve('browser-assert'),
util: require.resolve('util'),
},
// Set webpack to resolve symlinks based on whether the user has asked node to.
// This feels like it should be default out-of-the-box in webpack :shrug:
symlinks: !isPreservingSymlinks,
},
optimization: {
splitChunks: {
Expand Down
29 changes: 0 additions & 29 deletions scripts/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,27 +103,6 @@ const steps = {

const logger = console;

export const overrideMainConfig = async ({
cwd,
mainOverrides,
}: {
cwd: string;
mainOverrides: Parameters['mainOverrides'];
}) => {
logger.info(`📝 Overwriting main.js with the following configuration:`);
const configDir = path.join(cwd, '.storybook');
const mainConfigPath = getInterpretedFile(path.resolve(configDir, 'main'));
logger.debug(mainOverrides);
const mainConfig = await readConfig(mainConfigPath);

Object.keys(mainOverrides).forEach((field) => {
// NOTE: using setFieldNode and passing the output of babelParse()
mainConfig.setFieldNode([field], mainOverrides[field]);
});

await writeConfig(mainConfig);
};

const addPackageScripts = async ({
cwd,
scripts,
Expand Down Expand Up @@ -193,14 +172,6 @@ async function main() {
optionValues: { local: true, start: false },
});

// TODO -- work out exactly where this should happen
const code = '(c) => ({ ...c, resolve: { ...c.resolve, symlinks: false } })';
const mainOverrides = {
// @ts-ignore (not sure why TS complains here, it does exist)
webpackFinal: babelParse(code).program.body[0].expression,
};
await overrideMainConfig({ cwd, mainOverrides } as any);

await addPackageScripts({
cwd,
scripts: {
Expand Down

0 comments on commit 7aaa253

Please sign in to comment.