Skip to content

Commit

Permalink
feat(plugin-vite): add derefSymlinks option to config (#3632)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterekjs committed Jun 19, 2024
1 parent 620a6ae commit 131b414
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/plugin/vite/src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ export interface VitePluginConfig {
* Renderer process Vite configs.
*/
renderer: VitePluginRendererConfig[];
/**
* Whether symlinked dependencies should be dereferenced during the copying of node_modules. Defaults to false.
*/
derefSymlinks?: boolean;
}
4 changes: 4 additions & 0 deletions packages/plugin/vite/src/ViteConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ export default class ViteConfigGenerator {
return this.isProd ? 'production' : 'development';
}

get derefSymlinks(): boolean {
return this.pluginConfig.derefSymlinks ?? false;
}

async getBuildConfig(): Promise<UserConfig[]> {
if (!Array.isArray(this.pluginConfig.build)) {
throw new Error('"config.build" must be an Array');
Expand Down
4 changes: 3 additions & 1 deletion packages/plugin/vite/src/VitePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,11 @@ the generated files). Instead, it is ${JSON.stringify(pj.main)}`);
spaces: 2,
});

const dereference = this.configGenerator.derefSymlinks;

// Copy the dependencies in package.json
for (const dep of flatDependencies) {
await fs.copy(dep.src, path.resolve(buildPath, dep.dest));
await fs.copy(dep.src, path.resolve(buildPath, dep.dest), { dereference });
}
};

Expand Down
19 changes: 19 additions & 0 deletions packages/plugin/vite/test/ViteConfig_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,23 @@ describe('ViteConfigGenerator', () => {

expect(buildConfig1).deep.equal(buildConfig2);
});

it('derefSymlinks', () => {
const createGeneratorWithConfig = (config: Partial<VitePluginConfig>) => {
const _config: VitePluginConfig = { build: [], renderer: [], ...config };
return new ViteConfigGenerator(_config, configRoot, true);
};

const testCases = new Map<boolean, Partial<VitePluginConfig>>([
[false, {}],
[false, { derefSymlinks: false }],
[true, { derefSymlinks: true }],
]);

for (const [expectedResult, config] of testCases) {
const generator = createGeneratorWithConfig(config);

expect(generator.derefSymlinks).to.eq(expectedResult);
}
});
});

0 comments on commit 131b414

Please sign in to comment.