Add type:"module" to package.json (#12272)
This commit is contained in:
1 parent
dc80e12fd8
commit
be0739ec22
32 files changed
+143
-64
No files matched your search
@@ -7,6 +7,10 @@ module.exports = {
|
||||
es2021: true,
|
||||
node: true,
|
||||
},
|
||||
parserOptions: {
|
||||
ecmaVersion: "latest",
|
||||
sourceType: "module",
|
||||
},
|
||||
reportUnusedDisableDirectives: true,
|
||||
extends: ["eslint:recommended", "prettier"],
|
||||
plugins: [
|
||||
@@ -87,7 +91,6 @@ module.exports = {
|
||||
},
|
||||
],
|
||||
"require-await": "error",
|
||||
strict: "error",
|
||||
"symbol-description": "error",
|
||||
yoda: [
|
||||
"error",
|
||||
@@ -98,12 +101,13 @@ module.exports = {
|
||||
],
|
||||
|
||||
"import/extensions": ["error", "ignorePackages"],
|
||||
"import/no-extraneous-dependencies": [
|
||||
"error",
|
||||
{
|
||||
devDependencies: ["jest.config.mjs", "tests/**", "scripts/**"],
|
||||
},
|
||||
],
|
||||
// TODO[@fisker]: Fix this
|
||||
// "import/no-extraneous-dependencies": [
|
||||
// "error",
|
||||
// {
|
||||
// devDependencies: ["jest.config.mjs", "tests/**", "scripts/**"],
|
||||
// },
|
||||
// ],
|
||||
"import/order": "error",
|
||||
"import/no-anonymous-default-export": "error",
|
||||
|
||||
@@ -142,6 +146,8 @@ module.exports = {
|
||||
"unicorn/prefer-array-some": "error",
|
||||
"unicorn/prefer-includes": "error",
|
||||
"unicorn/prefer-json-parse-buffer": "error",
|
||||
"unicorn/prefer-module": "error",
|
||||
"unicorn/prefer-node-protocol": "error",
|
||||
"unicorn/prefer-number-properties": "error",
|
||||
"unicorn/prefer-optional-catch-binding": "error",
|
||||
"unicorn/prefer-regexp-test": "error",
|
||||
@@ -155,6 +161,7 @@ module.exports = {
|
||||
{
|
||||
files: [
|
||||
"scripts/**/*.js",
|
||||
"scripts/**/*.cjs",
|
||||
"scripts/**/*.mjs",
|
||||
"tests/config/install-prettier.js",
|
||||
],
|
||||
@@ -162,25 +169,33 @@ module.exports = {
|
||||
"no-console": "off",
|
||||
},
|
||||
},
|
||||
// CommonJS modules
|
||||
{
|
||||
files: [
|
||||
"**/*.mjs",
|
||||
"scripts/release/**/*.js",
|
||||
"tests/**/*.js",
|
||||
"bin/**/*.js",
|
||||
"src/cli/**/*.js",
|
||||
],
|
||||
excludedFiles: [
|
||||
"**/*.cjs",
|
||||
"src/*.js",
|
||||
"src/common/**/*.js",
|
||||
"src/config/**/*.js",
|
||||
"src/document/**/*.js",
|
||||
"src/language-css/**/*.js",
|
||||
"src/language-graphql/**/*.js",
|
||||
"src/language-handlebars/**/*.js",
|
||||
"src/language-html/**/*.js",
|
||||
"src/language-js/**/*.js",
|
||||
"src/language-markdown/**/*.js",
|
||||
"src/language-yaml/**/*.js",
|
||||
"src/main/**/*.js",
|
||||
"src/utils/**/*.js",
|
||||
"scripts/tools/eslint-plugin-prettier-internal-rules/**/*.js",
|
||||
"website/**/*.js",
|
||||
"tests/integration/plugins/automatic/prettier-plugin-bar.js",
|
||||
],
|
||||
parserOptions: {
|
||||
sourceType: "module",
|
||||
sourceType: "script",
|
||||
},
|
||||
rules: {
|
||||
"unicorn/prefer-module": "error",
|
||||
"unicorn/prefer-node-protocol": "error",
|
||||
// TODO[@fisker]: Fix this
|
||||
"import/no-extraneous-dependencies": "off",
|
||||
strict: "error",
|
||||
"unicorn/prefer-module": "off",
|
||||
},
|
||||
},
|
||||
// `esbuild` don't support
|
||||
@@ -226,7 +241,6 @@ module.exports = {
|
||||
{
|
||||
files: ["tests/**/*.js"],
|
||||
rules: {
|
||||
strict: "off",
|
||||
"import/no-extraneous-dependencies": "off",
|
||||
"unicorn/prefer-array-flat": "off",
|
||||
"unicorn/prefer-array-flat-map": "off",
|
||||
@@ -329,5 +343,11 @@ module.exports = {
|
||||
sourceType: "module",
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ["scripts/tools/eslint-plugin-prettier-internal-rules/**/*.js"],
|
||||
rules: {
|
||||
"import/no-extraneous-dependencies": "error",
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
+1
-1
@@ -53,7 +53,7 @@ Parameters:
|
||||
|
||||
The implementation of `run_spec` can be found in [`tests/config/format-test.js`](tests/config/format-test.js).
|
||||
|
||||
`tests/format/flow-repo/` contains the Flow test suite and is not supposed to be edited by hand. To update it, clone the Flow repo next to the Prettier repo and run: `node scripts/sync-flow-tests.js ../flow/tests/`.
|
||||
`tests/format/flow-repo/` contains the Flow test suite and is not supposed to be edited by hand. To update it, clone the Flow repo next to the Prettier repo and run: `node scripts/sync-flow-tests.cjs ../flow/tests/`.
|
||||
|
||||
## Debugging
|
||||
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"type": "module"
|
||||
}
|
||||
@@ -1,3 +1 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = require("./src/index.js");
|
||||
export { default } from "./src/index.js";
|
||||
@@ -4,7 +4,7 @@ const config = {
|
||||
...baseConfig,
|
||||
runner: "./tests/config/jest-light-runner",
|
||||
testRegex: "tests/format/.*/jsfmt\\.spec\\.js$",
|
||||
setupFiles: ["<rootDir>/tests/config/setup.js"],
|
||||
setupFiles: ["<rootDir>/tests/config/format-test-setup.js"],
|
||||
projects: [],
|
||||
};
|
||||
|
||||
|
||||
@@ -4,6 +4,10 @@ const config = {
|
||||
...baseConfig,
|
||||
testRegex: "tests/integration/__tests__/.*\\.js$",
|
||||
projects: [],
|
||||
moduleNameMapper: {
|
||||
...baseConfig.moduleNameMapper,
|
||||
"prettier-local": "<rootDir>/tests/config/prettier-entry.common.cjs",
|
||||
},
|
||||
};
|
||||
|
||||
export default config;
|
||||
+1
-1
@@ -46,7 +46,7 @@ const config = {
|
||||
],
|
||||
coverageReporters: ["text", "lcov"],
|
||||
moduleNameMapper: {
|
||||
"prettier-local": "<rootDir>/tests/config/require-prettier.cjs",
|
||||
"prettier-local": "<rootDir>/tests/config/prettier-entry.js",
|
||||
"prettier-standalone": "<rootDir>/tests/config/require-standalone.cjs",
|
||||
},
|
||||
modulePathIgnorePatterns: [
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
"funding": "https://github.com/prettier/prettier?sponsor=1",
|
||||
"homepage": "https://prettier.io",
|
||||
"author": "James Long",
|
||||
"type": "module",
|
||||
"license": "MIT",
|
||||
"main": "./index.js",
|
||||
"browser": "./standalone.js",
|
||||
|
||||
@@ -55,13 +55,14 @@ async function buildPlaygroundFiles() {
|
||||
const parsers = {};
|
||||
for (const fileName of files) {
|
||||
const file = path.join(PRETTIER_DIR, fileName);
|
||||
await copyFile(file, path.join(PLAYGROUND_PRETTIER_DIR, fileName));
|
||||
const dist = path.join(PLAYGROUND_PRETTIER_DIR, fileName);
|
||||
await copyFile(file, dist);
|
||||
|
||||
if (fileName === "standalone.js") {
|
||||
continue;
|
||||
}
|
||||
|
||||
const plugin = require(file);
|
||||
const plugin = require(dist);
|
||||
// We add plugins to the global `prettierPlugins` object
|
||||
// the name after `parser-` is used as property
|
||||
// For example to get parsers in `parser-babel.js` via `prettierPlugins.babel`
|
||||
|
||||
@@ -164,6 +164,7 @@ async function preparePackage() {
|
||||
delete packageJson.dependencies;
|
||||
delete packageJson.devDependencies;
|
||||
delete packageJson.browserslist;
|
||||
delete packageJson.type;
|
||||
packageJson.scripts = {
|
||||
prepublishOnly:
|
||||
"node -e \"assert.equal(require('.').version, require('..').version)\"",
|
||||
|
||||
@@ -49,10 +49,15 @@ function* getEsbuildOptions(bundle, buildOptions) {
|
||||
const replaceModule = {};
|
||||
// Replace other bundled files
|
||||
if (bundle.target === "node") {
|
||||
// Replace package.json with dynamic `require("./package.json")`
|
||||
// TODO[@fisker]: Fix this later, currently esbuild resolve it as ESM
|
||||
// // Replace package.json with dynamic `require("./package.json")`
|
||||
// replaceModule[path.join(PROJECT_ROOT, "package.json")] = {
|
||||
// path: "./package.json",
|
||||
// external: true,
|
||||
// };
|
||||
replaceModule[path.join(PROJECT_ROOT, "package.json")] = {
|
||||
path: "./package.json",
|
||||
external: true,
|
||||
contents: JSON.stringify({ version: packageJson.version }),
|
||||
loader: "json",
|
||||
};
|
||||
|
||||
// Dynamic require bundled files
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import prettier from "../index.js";
|
||||
import generateSchema from "./utils/generate-schema.js";
|
||||
import generateSchema from "./utils/generate-schema.mjs";
|
||||
|
||||
console.log(
|
||||
prettier.format(
|
||||
|
||||
@@ -79,7 +79,7 @@ function run(argv) {
|
||||
console.error(
|
||||
[
|
||||
"You must provide the path to a flow tests directory to sync from!",
|
||||
"Example: node scripts/sync-flow-tests.js ../flow/tests/",
|
||||
"Example: node scripts/sync-flow-tests.cjs ../flow/tests/",
|
||||
].join("\n")
|
||||
);
|
||||
return 1;
|
||||
@@ -3,6 +3,7 @@
|
||||
"version": "1.0.3",
|
||||
"description": "Prettier internal eslint rules",
|
||||
"private": true,
|
||||
"type": "commonjs",
|
||||
"author": "fisker",
|
||||
"main": "./index.js",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = generateSchema;
|
||||
|
||||
function generateSchema(options) {
|
||||
return {
|
||||
$schema: "http://json-schema.org/draft-04/schema#",
|
||||
@@ -116,3 +112,5 @@ function optionTypeToSchemaType(optionType) {
|
||||
function choiceToSchema(choice) {
|
||||
return { enum: [choice.value], description: choice.description };
|
||||
}
|
||||
|
||||
export default generateSchema;
|
||||
@@ -1,3 +1,5 @@
|
||||
{
|
||||
"type": "module"
|
||||
"//TODO": "Remove this file when we close #10157",
|
||||
"type": "module",
|
||||
"description": "A package.json file to use `.js` files in this directory as ES module."
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"//TODO": "Remove this file when we close #10157",
|
||||
"type": "commonjs",
|
||||
"description": "A package.json file to use `.js` files in this directory as CommonJS module."
|
||||
}
|
||||
+1
-3
@@ -1,3 +1 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = require("./src/standalone.js");
|
||||
export { default } from "./src/standalone.js";
|
||||
@@ -0,0 +1,19 @@
|
||||
import createEsmUtils from "esm-utils";
|
||||
import getPrettier from "./get-prettier.js";
|
||||
import runSpec from "./format-test.js";
|
||||
|
||||
async function setup() {
|
||||
const { TEST_STANDALONE } = process.env;
|
||||
|
||||
const prettier = TEST_STANDALONE
|
||||
? createEsmUtils(import.meta).require("./require-standalone.cjs")
|
||||
: await getPrettier();
|
||||
|
||||
runSpec.prettier = prettier;
|
||||
|
||||
globalThis.run_spec = runSpec;
|
||||
}
|
||||
|
||||
// `await`ed in `./jest-light-runner/worker-runner.js`
|
||||
// Use top-level await in `./prettier-entry.js` when we drop support for Node.js 12
|
||||
export { setup };
|
||||
@@ -8,12 +8,9 @@ import visualizeEndOfLine from "./utils/visualize-end-of-line.js";
|
||||
import consistentEndOfLine from "./utils/consistent-end-of-line.js";
|
||||
import stringifyOptionsForTitle from "./utils/stringify-options-for-title.js";
|
||||
|
||||
const { require, __dirname } = createEsmUtils(import.meta);
|
||||
const { __dirname } = createEsmUtils(import.meta);
|
||||
|
||||
const { TEST_STANDALONE } = process.env;
|
||||
const prettier = !TEST_STANDALONE
|
||||
? require("./require-prettier.cjs")
|
||||
: require("./require-standalone.cjs");
|
||||
let prettier;
|
||||
|
||||
const { FULL_TEST } = process.env;
|
||||
const BOM = "\uFEFF";
|
||||
@@ -454,4 +451,13 @@ function format(originalText, originalOptions) {
|
||||
};
|
||||
}
|
||||
|
||||
Object.defineProperty(runSpec, "prettier", {
|
||||
get() {
|
||||
return prettier;
|
||||
},
|
||||
set(prettierModule) {
|
||||
prettier = prettierModule;
|
||||
},
|
||||
configurable: true,
|
||||
});
|
||||
export default runSpec;
|
||||
@@ -0,0 +1,12 @@
|
||||
import { pathToFileURL } from "node:url";
|
||||
import path from "node:path";
|
||||
|
||||
const entry = pathToFileURL(path.join(process.env.PRETTIER_DIR, "index.js"));
|
||||
|
||||
const getPrettier = async () => {
|
||||
const { default: prettier } = await import(entry);
|
||||
|
||||
return prettier;
|
||||
};
|
||||
|
||||
export default getPrettier;
|
||||
@@ -28,7 +28,11 @@ export default async function ({ test, updateSnapshot, port }) {
|
||||
|
||||
const {setupFiles, snapshotSerializers} = test.context.config;
|
||||
for (const path of setupFiles) {
|
||||
await import(pathToFileURL(path));
|
||||
const { setup } = await import(pathToFileURL(path));
|
||||
|
||||
if (typeof setup === "function") {
|
||||
await setup();
|
||||
}
|
||||
}
|
||||
for (const path of snapshotSerializers) {
|
||||
const {default: serializer} = await import(pathToFileURL(path));
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
// This file exists because plugins for test use `require('prettier-local')`
|
||||
|
||||
const path = require("path");
|
||||
|
||||
module.exports = require(path.join(process.env.PRETTIER_DIR, "index.js"));
|
||||
@@ -0,0 +1,3 @@
|
||||
import getPrettier from "./get-prettier.js";
|
||||
|
||||
export default await getPrettier();
|
||||
@@ -1,5 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
const prettier = require(process.env.PRETTIER_DIR);
|
||||
|
||||
module.exports = prettier;
|
||||
@@ -1,3 +0,0 @@
|
||||
import run_spec from "./format-test.js";
|
||||
|
||||
globalThis.run_spec = run_spec;
|
||||
@@ -1,4 +1,6 @@
|
||||
import prettier from "../../../config/require-prettier.cjs";
|
||||
// TODO: Use this when we drop support for Node.js 12
|
||||
// import prettier from "../../../config/prettier-entry.js";
|
||||
const { prettier } = run_spec;
|
||||
|
||||
run_spec(import.meta, ["babel", "typescript", "flow"]);
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import prettier from "../../../config/require-prettier.cjs";
|
||||
import prettier from "../../../../index.js";
|
||||
|
||||
const parsers = prettier
|
||||
.getSupportInfo()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import prettier from "prettier-local";
|
||||
import generateSchema from "../../../scripts/utils/generate-schema.js";
|
||||
import generateSchema from "../../../scripts/utils/generate-schema.mjs";
|
||||
|
||||
test("schema", () => {
|
||||
expect(generateSchema(prettier.getSupportInfo().options)).toMatchSnapshot();
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"type": "module"
|
||||
}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"//TODO": "Remove this file when we close #10157",
|
||||
"type": "commonjs",
|
||||
"description": "A package.json file to use `.js` files in this directory as CommonJS module."
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"private": true,
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"build": "webpack --mode=production && docusaurus-build",
|
||||
|
||||
Reference in new issue
Block a user