Skip to content

Commit

Permalink
fix(resolve): fix typescript resolve patch
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Jul 23, 2020
1 parent f7c03c2 commit 1ef8097
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/compiler/bundle/core-resolve-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,28 +83,33 @@ export const coreResolvePlugin = (config: d.Config, compilerCtx: d.CompilerCtx,
async load(filePath) {
if (filePath && !filePath.startsWith('\0')) {
filePath = normalizeFsPath(filePath);

if (filePath === internalClient || filePath === internalHydrate) {
if (isRemoteUrl(compilerExe)) {
let code = await compilerCtx.fs.readFile(filePath);

if (typeof code !== 'string' && isRemoteUrl(compilerExe)) {
const url = getStencilModuleUrl(compilerExe, filePath);
return fetchModuleAsync(config.sys, compilerCtx.fs, packageVersions, url, filePath);
code = await fetchModuleAsync(config.sys, compilerCtx.fs, packageVersions, url, filePath);
}

let code = await compilerCtx.fs.readFile(normalizeFsPath(filePath));
const hydratedFlag = config.hydratedFlag;
if (hydratedFlag) {
const hydratedFlagHead = getHydratedFlagHead(hydratedFlag);
if (HYDRATED_CSS !== hydratedFlagHead) {
code = code.replace(HYDRATED_CSS, hydratedFlagHead);
if (hydratedFlag.name !== 'hydrated') {
code = code.replace(`.classList.add("hydrated")`, `.classList.add("${hydratedFlag.name}")`);
code = code.replace(`.classList.add('hydrated')`, `.classList.add('${hydratedFlag.name}')`);
code = code.replace(`.setAttribute("hydrated",`, `.setAttribute("${hydratedFlag.name}",`);
code = code.replace(`.setAttribute('hydrated',`, `.setAttribute('${hydratedFlag.name}',`);
if (typeof code === 'string') {
const hydratedFlag = config.hydratedFlag;
if (hydratedFlag) {
const hydratedFlagHead = getHydratedFlagHead(hydratedFlag);
if (HYDRATED_CSS !== hydratedFlagHead) {
code = code.replace(HYDRATED_CSS, hydratedFlagHead);
if (hydratedFlag.name !== 'hydrated') {
code = code.replace(`.classList.add("hydrated")`, `.classList.add("${hydratedFlag.name}")`);
code = code.replace(`.classList.add('hydrated')`, `.classList.add('${hydratedFlag.name}')`);
code = code.replace(`.setAttribute("hydrated",`, `.setAttribute("${hydratedFlag.name}",`);
code = code.replace(`.setAttribute('hydrated',`, `.setAttribute('${hydratedFlag.name}',`);
}
}
} else {
code = code.replace(HYDRATED_CSS, '{}');
}
} else {
code = code.replace(HYDRATED_CSS, '{}');
}

return code;
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/compiler/sys/typescript/typescript-resolve-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ export const patchedTsResolveModule = (
let resolvedFileName = join(containingDir, moduleName);
resolvedFileName = normalizePath(ensureExtension(resolvedFileName, containingFile));

if (isAbsolute(resolvedFileName) && !inMemoryFs.accessSync(resolvedFileName)) {
return null;
}

if (!isAbsolute(resolvedFileName) && !resolvedFileName.startsWith('.') && !resolvedFileName.startsWith('/')) {
resolvedFileName = './' + resolvedFileName;
}
Expand All @@ -94,6 +98,7 @@ export const patchedTsResolveModule = (
},
};
(rtn as any).failedLookupLocations = [];

return rtn;
}

Expand Down

0 comments on commit 1ef8097

Please sign in to comment.