Skip to content

Commit 8e7a23a

Browse files
authored
Pass the containing URL to importers under some circumstances (#246)
Closes #3247
1 parent ffa9947 commit 8e7a23a

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

lib/src/importer-registry.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class ImporterRegistry<sync extends 'sync' | 'async'> {
4545
register(
4646
importer: Importer<sync> | FileImporter<sync>
4747
): proto.InboundMessage_CompileRequest_Importer {
48-
const response = new proto.InboundMessage_CompileRequest_Importer();
48+
const message = new proto.InboundMessage_CompileRequest_Importer();
4949
if ('canonicalize' in importer) {
5050
if ('findFileUrl' in importer) {
5151
throw new Error(
@@ -54,14 +54,18 @@ export class ImporterRegistry<sync extends 'sync' | 'async'> {
5454
);
5555
}
5656

57-
response.importer = {case: 'importerId', value: this.id};
57+
message.importer = {case: 'importerId', value: this.id};
58+
message.nonCanonicalScheme =
59+
typeof importer.nonCanonicalScheme === 'string'
60+
? [importer.nonCanonicalScheme]
61+
: importer.nonCanonicalScheme ?? [];
5862
this.importersById.set(this.id, importer);
5963
} else {
60-
response.importer = {case: 'fileImporterId', value: this.id};
64+
message.importer = {case: 'fileImporterId', value: this.id};
6165
this.fileImportersById.set(this.id, importer);
6266
}
6367
this.id += 1;
64-
return response;
68+
return message;
6569
}
6670

6771
/** Handles a canonicalization request. */
@@ -78,6 +82,9 @@ export class ImporterRegistry<sync extends 'sync' | 'async'> {
7882
return thenOr(
7983
importer.canonicalize(request.url, {
8084
fromImport: request.fromImport,
85+
containingUrl: request.containingUrl
86+
? new URL(request.containingUrl)
87+
: null,
8188
}),
8289
url =>
8390
new proto.InboundMessage_CanonicalizeResponse({
@@ -157,6 +164,9 @@ export class ImporterRegistry<sync extends 'sync' | 'async'> {
157164
return thenOr(
158165
importer.findFileUrl(request.url, {
159166
fromImport: request.fromImport,
167+
containingUrl: request.containingUrl
168+
? new URL(request.containingUrl)
169+
: null,
160170
}),
161171
url => {
162172
if (!url) return new proto.InboundMessage_FileImportResponse();

tool/get-language-repo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export async function getLanguageRepo(
3232
// Workaround for https://github.com/shelljs/shelljs/issues/198
3333
// This file is a symlink which gets messed up by `shell.cp` (called from
3434
// `utils.link`) on Windows.
35-
shell.rm('build/sass/spec/README.md');
35+
if (process.platform === 'win32') shell.rm('build/sass/spec/README.md');
3636

3737
await utils.link('build/sass/js-api-doc', p.join(outPath, 'sass'));
3838

tool/utils.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// MIT-style license that can be found in the LICENSE file or at
33
// https://opensource.org/licenses/MIT.
44

5-
import {promises as fs, existsSync} from 'fs';
5+
import {promises as fs, existsSync, lstatSync} from 'fs';
66
import * as p from 'path';
77
import * as shell from 'shelljs';
88

@@ -17,13 +17,21 @@ export function fetchRepo(options: {
1717
outPath: string;
1818
ref: string;
1919
}): void {
20-
if (!existsSync(p.join(options.outPath, options.repo))) {
20+
const path = p.join(options.outPath, options.repo);
21+
if (lstatSync(path).isSymbolicLink() && existsSync(p.join(path, '.git'))) {
22+
throw (
23+
`${path} is a symlink to a git repo, not overwriting.\n` +
24+
`Run "rm ${path}" and try again.`
25+
);
26+
}
27+
28+
if (!existsSync(path)) {
2129
console.log(`Cloning ${options.repo} into ${options.outPath}.`);
2230
shell.exec(
2331
`git clone \
2432
--depth=1 \
2533
https://github.com/sass/${options.repo} \
26-
${p.join(options.outPath, options.repo)}`,
34+
${path}`,
2735
{silent: true}
2836
);
2937
}
@@ -35,7 +43,7 @@ export function fetchRepo(options: {
3543
`git fetch --depth=1 origin ${options.ref} && git reset --hard FETCH_HEAD`,
3644
{
3745
silent: true,
38-
cwd: p.join(options.outPath, options.repo),
46+
cwd: path,
3947
}
4048
);
4149
}

0 commit comments

Comments
 (0)