Skip to content

Improves react lite theme loader's path resolver #2950 #2954

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

Closed
wants to merge 1 commit into from
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
16 changes: 13 additions & 3 deletions jscomp/bsb/templates/react-lite/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,16 @@ function getPackageName(id) {
}
return id.substring(0, index)
}
function getPackageJsPromise(id, parent) {
function getLinkPath(id, parent, packageInfo) {
var idNodeModulesPrefix = './node_modules/' + id
var link = getPathWithJsSuffix(idNodeModulesPrefix, parent)
if (!id.includes("/")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this mean, is it an ad-hoc optimization?

var mainFile = packageInfo.main || "index.js"
return getPathWithJsSuffix(`${idNodeModulesPrefix}/${mainFile}`, parent)
} else {
return getPathWithJsSuffix(idNodeModulesPrefix, parent)
}
}
function getPackageJsPromise(id, parent) {
if (parent.endsWith('node_modules/')) {
// impossible that `node_modules/node_modules/xx/x
// return falsePromise
Expand All @@ -270,10 +277,13 @@ function getPackageJsPromise(id, parent) {
function (text) {
if (text !== false) {
// package indeed exist
var packageInfo = JSON.parse(text);
var link = getLinkPath(id, parent, packageInfo);
return cachedFetch(link).then(function (text) {
if (text !== false) {
return { text, link }
} else if (!id.endsWith('.js')) {
var idNodeModulesPrefix = "./node_modules/" + id;
var linkNew = getPathWithJsSuffix(idNodeModulesPrefix + `/index.js`, parent)
return cachedFetch(linkNew)
.then(function (text) {
Expand Down Expand Up @@ -310,7 +320,7 @@ function getModulePromise(id, parent) {
if (!done) {
return visitIdLocation(id, parent, function () {
if (id[0] != '.') { // package path
return getPackageJsPromise(id, parent)
return getPackageJsPromise(id, '')
} else { // relative path, one shot resolve
let link = getPathWithJsSuffix(id, parent)
return cachedFetch(link).then(
Expand Down