Skip to content

Commit 58f5ba9

Browse files
committed
feat(vite): improve workspace resolutions
1 parent 9ba2421 commit 58f5ba9

File tree

7 files changed

+24
-11
lines changed

7 files changed

+24
-11
lines changed

packages/vite/configuration/angular.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ export const angularConfig = ({ mode }): UserConfig => {
305305

306306
const enableRollupLinker = process.env.NS_ENABLE_ROLLUP_LINKER === '1' || process.env.NS_ENABLE_ROLLUP_LINKER === 'true' || hmrActive;
307307

308-
return mergeConfig(baseConfig({ mode }), {
308+
return mergeConfig(baseConfig({ mode, flavor: 'angular' }), {
309309
plugins: [...plugins, ...(enableRollupLinker ? [angularRollupLinker(process.cwd())] : []), renderChunkLinker, postLinker],
310310
// Always alias fesm2022 deep imports to package root so vendor bridge can externalize properly
311311
resolve: {

packages/vite/configuration/base.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,12 @@ export const baseConfig = ({ mode, flavor }: { mode: string; flavor?: string }):
331331
// Simplified CommonJS handling - let Vite's optimizeDeps do the heavy lifting
332332
commonjs({
333333
include: [/node_modules/],
334-
// Force specific problematic modules to be treated as CommonJS
334+
// Let Rollup/Vite decide default mapping for CommonJS modules.
335335
requireReturnsDefault: 'auto',
336336
defaultIsModuleExports: 'auto',
337337
transformMixedEsModules: true,
338338
// Ignore optional dependencies that are meant to fail gracefully
339-
ignore: ['@nativescript/android', '@nativescript/ios'],
339+
ignore: ['@nativescript/android', '@nativescript/ios', '@nativescript/visionos'],
340340
}),
341341
nsConfigAsJsonPlugin(),
342342
NativeScriptPlugin({ platform }),

packages/vite/configuration/react.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export default React;
8686
];
8787

8888
export const reactConfig = ({ mode }): UserConfig => {
89-
return mergeConfig(baseConfig({ mode }), {
89+
return mergeConfig(baseConfig({ mode, flavor: 'react' }), {
9090
plugins,
9191
});
9292
};

packages/vite/configuration/solid.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const plugins = [
4747
];
4848

4949
export const solidConfig = ({ mode }): UserConfig => {
50-
return mergeConfig(baseConfig({ mode }), {
50+
return mergeConfig(baseConfig({ mode, flavor: 'solid' }), {
5151
plugins,
5252
});
5353
};

packages/vite/configuration/typescript.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ function createXmlLoaderPlugin(): Plugin {
154154
}
155155

156156
export const typescriptConfig = ({ mode }): UserConfig => {
157-
return mergeConfig(baseConfig({ mode }), {
157+
return mergeConfig(baseConfig({ mode, flavor: 'typescript' }), {
158158
plugins: [createXmlLoaderPlugin(), createBundlerContextPlugin()],
159159
});
160160
};

packages/vite/configuration/vue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const vueConfig = ({ mode }): UserConfig => {
2121
const isDevMode = targetMode === 'development';
2222
const hmrActive = isDevMode && !!cliFlags.hmr;
2323

24-
return mergeConfig(baseConfig({ mode }), {
24+
return mergeConfig(baseConfig({ mode, flavor: 'vue' }), {
2525
plugins: [
2626
{
2727
...alias({

packages/vite/helpers/main-entry.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,21 @@ const mainEntryRelPosix = (() => {
2222
const flavor = getProjectFlavor() as string;
2323

2424
// Optional polyfills support (non-HMR specific but dev friendly)
25-
const polyfillsPath = getProjectFilePath(getProjectAppRelativePath('polyfills.ts'));
26-
const polyfillsExists = fs.existsSync(polyfillsPath);
25+
// Resolve polyfills relative to the main entry directory so it works both for standalone projects and monorepos/workspaces where the workspace root and app root differ.
26+
// We keep both the absolute filesystem path (for existsSync) and a project-root-relative POSIX path (for the import specifier used in Vite).
27+
const mainEntryDir = path.dirname(mainEntry);
28+
const polyfillsFsPath = path.resolve(mainEntryDir, 'polyfills.ts');
29+
const polyfillsExists = fs.existsSync(polyfillsFsPath);
30+
const polyfillsImportSpecifier = (() => {
31+
try {
32+
// Normalize to "/..." posix-style (similar to mainEntryRelPosix)
33+
const rel = path.relative(projectRoot, polyfillsFsPath).replace(/\\/g, '/');
34+
return ('/' + rel).replace(/\/+/g, '/');
35+
} catch {
36+
// Fallback to a simple relative specifier next to main entry
37+
return './polyfills.ts';
38+
}
39+
})();
2740

2841
const VIRTUAL_ID = 'virtual:entry-with-polyfills';
2942
const RESOLVED = '\0' + VIRTUAL_ID;
@@ -167,9 +180,9 @@ export function mainEntryPlugin(opts: { platform: 'ios' | 'android' | 'visionos'
167180

168181
// ---- Optional polyfills ----
169182
if (polyfillsExists) {
170-
imports += `import '${polyfillsPath}';\n`;
183+
imports += `import '${polyfillsImportSpecifier}';\n`;
171184
if (opts.verbose) {
172-
imports += `console.info('[ns-entry] polyfills imported from', ${JSON.stringify(polyfillsPath)});\n`;
185+
imports += `console.info('[ns-entry] polyfills imported from', ${JSON.stringify(polyfillsImportSpecifier)});\n`;
173186
}
174187
} else if (opts.verbose) {
175188
imports += "console.info('[ns-entry] no polyfills file found');\n";

0 commit comments

Comments
 (0)