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

feat: add package files support #6942

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions packages/ice/src/service/preBundleDeps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ export async function bundleDeps(options:
});
}

function resolveAbsoluteImport(entry: string, pkgDir: string, pkgJSON) {
const relativePath = entry.replace(`${pkgJSON.name}/`, '');
const absolutePath = path.join(pkgDir, relativePath);
return fse.pathExistsSync(absolutePath) ? relativePath : '';
}

export function resolvePackageESEntry(depId: string, pkgPath: string, alias: TaskConfig<Config>['config']['alias']) {
const pkgJSON = fse.readJSONSync(pkgPath);
const pkgDir = path.dirname(pkgPath);
Expand All @@ -185,8 +191,8 @@ export function resolvePackageESEntry(depId: string, pkgPath: string, alias: Tas
// rax/element -> ./element
const entry = aliasKey ? depId.replace(new RegExp(`^${aliasKey}`), '.') : depId;
// resolve "exports.import" field or "module" field
const resolvedEntryPoint = (resolveExports(pkgJSON, entry) || resolveLegacy(pkgJSON) || 'index.js') as string;
const entryPointPath = path.join(pkgDir, resolvedEntryPoint);
const resolvedEntryPoint = resolveExports(pkgJSON, entry) || resolveAbsoluteImport(entry, pkgDir, pkgJSON) || resolveLegacy(pkgJSON);
const entryPointPath = path.join(pkgDir, typeof resolvedEntryPoint === 'string' ? resolvedEntryPoint : 'index.js');
return entryPointPath;
}

Expand Down
Loading