Skip to content

Commit

Permalink
fix(sdks): support Prettier v3 (#5411)
Browse files Browse the repository at this point in the history
**What's the problem this PR addresses?**

Prettier v3 changes the path to the entry point so we need to update the
path used.

**How did you fix it?**

Updated the SDK to require `prettier` and let Node.js find the entry
point.

**Checklist**
- [x] I have read the [Contributing
Guide](https://yarnpkg.com/advanced/contributing).
- [x] I have set the packages that need to be released for my changes to
be effective.
- [x] I will check that all automated PR checks pass before the PR gets
reviewed.
  • Loading branch information
merceyz authored Jun 25, 2023
1 parent 6fc86f6 commit 4e6f983
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
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

0 comments on commit 4e6f983

Please sign in to comment.