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

use template needs to work also with starter template #9261

Merged
merged 3 commits into from
Jun 6, 2024

Conversation

cderv
Copy link
Collaborator

@cderv cderv commented Apr 3, 2024

quarto use template can be used to copy files from a remote even if it does not have extension

Tweaks from #8764 regarding installation of extension only needs to happen if there is an _extension folder

#8764 uses

// Compute extensions that need to be installed (and confirm any)
// changes
const extDir = join(stagedDir, kExtensionDir);
// Determine whether we can update extensions
const templateExtensions = await readExtensions(extDir);
const installedExtensions = [];
let installExtensions = false;
if (templateExtensions.length > 0) {
installExtensions = await confirmInstallation(
templateExtensions,
outputDirectory,
{
allowPrompt: options.prompt !== false,
throw: true,
message: "The template requires the following changes to extensions:",
},
);
if (!installExtensions) {
return;
}
}

This PR makes sure that readExtensions returns empty list when extensionsDirectory doesn't exists. This should prevent any similar issue when using readExtensions in the future.

closes #9256

I did not add to changelog because it was only broken by #8764 merged in 1.5.15

@cderv cderv requested review from cscheid and dragonstyle April 3, 2024 11:14
Copy link
Collaborator

@cscheid cscheid left a comment

Choose a reason for hiding this comment

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

Looks good. I searched for additional instances of using extensionsDirectory and this seemed to be the only one.

@cderv
Copy link
Collaborator Author

cderv commented Apr 3, 2024

This would be readExtensions() usage maybe to look for.

I am seeing some occurrences where we externally do the existence-checking

// Read any embedded extension
const embeddedExtensions = existsSync(join(extensionDir, kExtensionDir))
? await readExtensions(join(extensionDir, kExtensionDir))
: [];

const existingExtensionsDir = join(installDir, kExtensionDir);
if (Deno.statSync(existingExtensionsDir).isDirectory) {
const existingExtensions = await readExtensions(
join(installDir, kExtensionDir),
);
return existingExtensions;

Looking deeper we do have this helper

// Is this _extensions or does this contain _extensions?
const extensionDir = (path: string) => {
if (basename(path) === kExtensionDir) {
// If this is pointing to an _extensions dir, use that
return path;
} else {
// Otherwise, add _extensions to this and use that
const extDir = join(path, kExtensionDir);
if (existsSync(extDir) && Deno.statSync(extDir).isDirectory) {
return extDir;
} else {
return path;
}
}
};

But it was modified not to return undefined (53ef1d9), which seems odd to me as we still checked for it in some places and it makes more sense 🤔

Anyhow, I am thinking now that this fix should probably be more scoped to template.ts by just reading if the dir exists

Or I should check all call to readExtensions()

@cderv
Copy link
Collaborator Author

cderv commented Apr 3, 2024

Or I should check all call to readExtensions()

I went with that, aiming at cleaning some part of our code with some refactoring.

@cderv cderv force-pushed the use-template-starter branch from 7143d22 to 74f7fd9 Compare June 4, 2024 15:06
cderv added 2 commits June 4, 2024 17:06
`quarto use template` can be used to copy files from a remote even if it does not have extension

Tweaks from #8764 regarding installation of extension only needs to happen if there is an `_extension` folder
@cderv cderv force-pushed the use-template-starter branch from 74f7fd9 to def13d0 Compare June 4, 2024 15:07
@cderv cderv force-pushed the use-template-starter branch from a22388f to 4d6e132 Compare June 5, 2024 08:09
@cderv cderv force-pushed the use-template-starter branch from 4d6e132 to 220f199 Compare June 5, 2024 08:10
@cderv cderv merged commit 13d3126 into main Jun 6, 2024
47 checks passed
@cderv cderv deleted the use-template-starter branch June 6, 2024 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

quarto use template no longer works for directories without a _extensions/ folder
2 participants