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

fix(sdks): support Prettier v3 #5411

Merged
merged 2 commits into from
Jun 25, 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
2 changes: 2 additions & 0 deletions .yarn/versions/5a966911.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
releases:
"@yarnpkg/sdks": patch
5 changes: 3 additions & 2 deletions packages/yarnpkg-sdks/sources/generateSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export class Wrapper {
this.target = target;
}

async writeManifest() {
async writeManifest(rawManifest: Record<string, any> = {}) {
const absWrapperPath = ppath.join(this.target, this.name, `package.json`);

const topLevelInformation = this.pnpApi.getPackageInformation(this.pnpApi.topLevel)!;
Expand All @@ -224,10 +224,11 @@ export class Wrapper {
version: `${manifest.version}-sdk`,
main: manifest.main,
type: `commonjs`,
...rawManifest,
});
}

async writeBinary(relPackagePath: PortablePath, options: TemplateOptions = {}) {
async writeBinary(relPackagePath: PortablePath, options: TemplateOptions & {requirePath?: PortablePath} = {}) {
await this.writeFile(relPackagePath, {...options, mode: 0o755});
}

Expand Down
14 changes: 11 additions & 3 deletions packages/yarnpkg-sdks/sources/sdks/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,25 @@ export const generateEslintBaseWrapper: GenerateBaseWrapper = async (pnpApi: Pnp
await wrapper.writeManifest();

await wrapper.writeBinary(`bin/eslint.js` as PortablePath);
await wrapper.writeFile(`lib/api.js` as PortablePath, {requirePath: `` as PortablePath});
await wrapper.writeFile(`lib/api.js` as PortablePath, {
// Empty path to use the entrypoint and let Node.js resolve the correct path itself
requirePath: `` as PortablePath,
});

return wrapper;
};

export const generatePrettierBaseWrapper: GenerateBaseWrapper = async (pnpApi: PnpApi, target: PortablePath) => {
const wrapper = new Wrapper(`prettier` as PortablePath, {pnpApi, target});

await wrapper.writeManifest();
await wrapper.writeManifest({
main: `./index.js`,
});

await wrapper.writeBinary(`index.js` as PortablePath);
await wrapper.writeBinary(`index.js` as PortablePath, {
// Empty path to use the entrypoint and let Node.js resolve the correct path itself
requirePath: `` as PortablePath,
});

return wrapper;
};
Expand Down