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

Pass the containing URL to importers under some circumstances #246

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
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
18 changes: 14 additions & 4 deletions lib/src/importer-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class ImporterRegistry<sync extends 'sync' | 'async'> {
register(
importer: Importer<sync> | FileImporter<sync>
): proto.InboundMessage_CompileRequest_Importer {
const response = new proto.InboundMessage_CompileRequest_Importer();
const message = new proto.InboundMessage_CompileRequest_Importer();
if ('canonicalize' in importer) {
if ('findFileUrl' in importer) {
throw new Error(
Expand All @@ -54,14 +54,18 @@ export class ImporterRegistry<sync extends 'sync' | 'async'> {
);
}

response.importer = {case: 'importerId', value: this.id};
message.importer = {case: 'importerId', value: this.id};
message.nonCanonicalScheme =
typeof importer.nonCanonicalScheme === 'string'
? [importer.nonCanonicalScheme]
: importer.nonCanonicalScheme ?? [];
this.importersById.set(this.id, importer);
} else {
response.importer = {case: 'fileImporterId', value: this.id};
message.importer = {case: 'fileImporterId', value: this.id};
this.fileImportersById.set(this.id, importer);
}
this.id += 1;
return response;
return message;
}

/** Handles a canonicalization request. */
Expand All @@ -78,6 +82,9 @@ export class ImporterRegistry<sync extends 'sync' | 'async'> {
return thenOr(
importer.canonicalize(request.url, {
fromImport: request.fromImport,
containingUrl: request.containingUrl
? new URL(request.containingUrl)
: null,
}),
url =>
new proto.InboundMessage_CanonicalizeResponse({
Expand Down Expand Up @@ -157,6 +164,9 @@ export class ImporterRegistry<sync extends 'sync' | 'async'> {
return thenOr(
importer.findFileUrl(request.url, {
fromImport: request.fromImport,
containingUrl: request.containingUrl
? new URL(request.containingUrl)
: null,
}),
url => {
if (!url) return new proto.InboundMessage_FileImportResponse();
Expand Down
2 changes: 1 addition & 1 deletion tool/get-language-repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function getLanguageRepo(
// Workaround for https://github.com/shelljs/shelljs/issues/198
// This file is a symlink which gets messed up by `shell.cp` (called from
// `utils.link`) on Windows.
shell.rm('build/sass/spec/README.md');
if (process.platform === 'win32') shell.rm('build/sass/spec/README.md');
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason why this is no longer necessary on Linux/Mac?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was only ever present as a workaround for a Windows issue in the first place (see the comment above).


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

Expand Down
16 changes: 12 additions & 4 deletions tool/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

import {promises as fs, existsSync} from 'fs';
import {promises as fs, existsSync, lstatSync} from 'fs';
import * as p from 'path';
import * as shell from 'shelljs';

Expand All @@ -17,13 +17,21 @@ export function fetchRepo(options: {
outPath: string;
ref: string;
}): void {
if (!existsSync(p.join(options.outPath, options.repo))) {
const path = p.join(options.outPath, options.repo);
if (lstatSync(path).isSymbolicLink() && existsSync(p.join(path, '.git'))) {
throw (
`${path} is a symlink to a git repo, not overwriting.\n` +
`Run "rm ${path}" and try again.`
);
}

if (!existsSync(path)) {
console.log(`Cloning ${options.repo} into ${options.outPath}.`);
shell.exec(
`git clone \
--depth=1 \
https://github.com/sass/${options.repo} \
${p.join(options.outPath, options.repo)}`,
${path}`,
{silent: true}
);
}
Expand All @@ -35,7 +43,7 @@ export function fetchRepo(options: {
`git fetch --depth=1 origin ${options.ref} && git reset --hard FETCH_HEAD`,
{
silent: true,
cwd: p.join(options.outPath, options.repo),
cwd: path,
}
);
}
Expand Down
Loading