Skip to content

Commit

Permalink
internal: Use yarn pnp
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed Mar 27, 2023
1 parent 230c1b1 commit 281a282
Show file tree
Hide file tree
Showing 17 changed files with 212 additions and 30 deletions.
13 changes: 9 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

{
"eslint.nodePath": "node_modules",
"eslint.nodePath": ".yarn/sdks",
"eslint.runtime": "node",
"typescript.format.enable": true,
"typescript.validate.enable": true,
"typescript.tsdk": "./node_modules/typescript/lib",
"typescript.tsdk": ".yarn/sdks/typescript/lib",
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[javascript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
Expand All @@ -23,5 +22,11 @@
],
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
},
"search.exclude": {
"**/.yarn": true,
"**/.pnp.*": true
},
"prettier.prettierPath": ".yarn/sdks/prettier/index.js",
"typescript.enablePromptUseWorkspaceTsdk": true
}
20 changes: 20 additions & 0 deletions .yarn/sdks/eslint/bin/eslint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env node

const {existsSync} = require(`fs`);
const {createRequire} = require(`module`);
const {resolve} = require(`path`);

const relPnpApiPath = "../../../../.pnp.cjs";

const absPnpApiPath = resolve(__dirname, relPnpApiPath);
const absRequire = createRequire(absPnpApiPath);

if (existsSync(absPnpApiPath)) {
if (!process.versions.pnp) {
// Setup the environment to be able to require eslint/bin/eslint.js
require(absPnpApiPath).setup();
}
}

// Defer to the real eslint/bin/eslint.js your application uses
module.exports = absRequire(`eslint/bin/eslint.js`);
6 changes: 6 additions & 0 deletions .yarn/sdks/eslint/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "eslint",
"version": "8.36.0-sdk",
"main": "./lib/api.js",
"type": "commonjs"
}
5 changes: 5 additions & 0 deletions .yarn/sdks/integrations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This file is automatically generated by @yarnpkg/sdks.
# Manual changes might be lost!

integrations:
- vscode
20 changes: 20 additions & 0 deletions .yarn/sdks/prettier/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env node

const {existsSync} = require(`fs`);
const {createRequire} = require(`module`);
const {resolve} = require(`path`);

const relPnpApiPath = "../../../.pnp.cjs";

const absPnpApiPath = resolve(__dirname, relPnpApiPath);
const absRequire = createRequire(absPnpApiPath);

if (existsSync(absPnpApiPath)) {
if (!process.versions.pnp) {
// Setup the environment to be able to require prettier/index.js
require(absPnpApiPath).setup();
}
}

// Defer to the real prettier/index.js your application uses
module.exports = absRequire(`prettier/index.js`);
6 changes: 6 additions & 0 deletions .yarn/sdks/prettier/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "prettier",
"version": "2.8.7-sdk",
"main": "./index.js",
"type": "commonjs"
}
20 changes: 20 additions & 0 deletions .yarn/sdks/typescript/bin/tsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env node

const {existsSync} = require(`fs`);
const {createRequire} = require(`module`);
const {resolve} = require(`path`);

const relPnpApiPath = "../../../../.pnp.cjs";

const absPnpApiPath = resolve(__dirname, relPnpApiPath);
const absRequire = createRequire(absPnpApiPath);

if (existsSync(absPnpApiPath)) {
if (!process.versions.pnp) {
// Setup the environment to be able to require typescript/bin/tsc
require(absPnpApiPath).setup();
}
}

// Defer to the real typescript/bin/tsc your application uses
module.exports = absRequire(`typescript/bin/tsc`);
20 changes: 20 additions & 0 deletions .yarn/sdks/typescript/bin/tsserver
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env node

const {existsSync} = require(`fs`);
const {createRequire} = require(`module`);
const {resolve} = require(`path`);

const relPnpApiPath = "../../../../.pnp.cjs";

const absPnpApiPath = resolve(__dirname, relPnpApiPath);
const absRequire = createRequire(absPnpApiPath);

if (existsSync(absPnpApiPath)) {
if (!process.versions.pnp) {
// Setup the environment to be able to require typescript/bin/tsserver
require(absPnpApiPath).setup();
}
}

// Defer to the real typescript/bin/tsserver your application uses
module.exports = absRequire(`typescript/bin/tsserver`);
6 changes: 6 additions & 0 deletions .yarn/sdks/typescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "typescript",
"version": "5.0.2-sdk",
"main": "./lib/typescript.js",
"type": "commonjs"
}
8 changes: 7 additions & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ changesetIgnorePatterns:
- "**/__tests__/**"
- "**/*.md"

nodeLinker: node-modules
nodeLinker: pnp
pnpEnableEsmLoader: true

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
Expand All @@ -14,4 +15,9 @@ plugins:
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: "@yarnpkg/plugin-workspace-tools"

packageExtensions:
"@ant-design/pro-layout@*":
dependencies:
"@ant-design/cssinjs": ^1.6.2

yarnPath: .yarn/releases/yarn-3.5.0.cjs
3 changes: 3 additions & 0 deletions examples/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
"@storybook/addon-links": "7.0.0-rc.8",
"@storybook/addon-mdx-gfm": "7.0.0-rc.8",
"@storybook/addons": "7.0.0-rc.8",
"@storybook/channel-postmessage": "7.0.0-rc.8",
"@storybook/channel-websocket": "7.0.0-rc.8",
"@storybook/preview-api": "7.0.0-rc.8",
"@storybook/react": "7.0.0-rc.8",
"@types/babel__core": "^7.20.0",
"@types/classnames": "2.3.1",
Expand Down
5 changes: 0 additions & 5 deletions examples/typescript/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@
"@standard-endpoint/github/*": ["github/*"]
} /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */,
//"rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
"typeRoots": [
"node_modules/@types",
"../../node_modules/@types",
"./src/typings"
] /* List of folders to include type definitions from. */,

"types": [
"jest",
Expand Down
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"@types/node": "^18.15.9",
"@typescript-eslint/eslint-plugin": "5.56.0",
"@typescript-eslint/parser": "5.56.0",
"babel-loader": "9.1.2",
"babel-plugin-module-resolver": "5.0.0",
"babel-plugin-root-import": "6.6.0",
"conventional-changelog-anansi": "0.2.0",
Expand All @@ -57,8 +56,6 @@
"lint-staged": "13.2.0",
"prettier": "2.8.7",
"typescript": "5.0.2",
"webpack": "5.76.3",
"webpack-cli": "5.0.1",
"webpack-dev-server": "4.13.1"
},
"resolutions": {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-preset-anansi/src/jest-preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module.exports = {
'/node_modules/(?!@babel/runtime)',
'\\.pnp\\.[^\\/]+$',
],
resolver: require.resolve(`jest-pnp-resolver`),
resolver: require.resolve(`./resolver`),
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(m|c)?(j|t)sx?$',
coveragePathIgnorePatterns: ['node_modules'],
moduleFileExtensions: [
Expand Down
21 changes: 21 additions & 0 deletions packages/jest-preset-anansi/src/resolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const pnpResolve = require('jest-pnp-resolver');
const path = require('path');

module.exports = (request: string, options: Record<string, any>) => {
if (
options.paths &&
Array.isArray(options.paths) &&
!['.', '/'].includes(request[0])
) {
for (const rootPath of options.paths) {
try {
const p = path.join(rootPath, request);
return require.resolve(p);
// eslint-disable-next-line no-empty
} catch (e) {}
}
}

return pnpResolve(request, options);
};
8 changes: 7 additions & 1 deletion packages/storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,17 @@
"@anansi/webpack-config": "^13.0.0 || ^14.0.0 || ^15.0.0",
"@rest-hooks/react": "^6.0.0 || ^7.0.0",
"@types/react": "^17.0.40 || ^18.0.0",
"react": "^18.0.0"
"@types/react-dom": "^17.0.40 || ^18.0.0",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"webpack": "*"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
},
"engines": {
Expand Down
Loading

0 comments on commit 281a282

Please sign in to comment.