Skip to content

Commit 69a68d8

Browse files
shufofisker
andauthored
fix: make /standalone entry work with require() (prettier#2247)
* chore: πŸ€– build cjs output for backward compatibility This commit adds cjs output to rollup config. * chore: πŸ€– add mapping for standalone.cjs * chore: πŸ€– include standalone.cjs as package source * chore: πŸ€– migrate .js files to .mjs * chore: πŸ€– disable ESM as default * refactor: πŸ’‘ delete unnecessary export * chore: πŸ€– revert build config * chore: πŸ€– add require to exports Without this require, vscode-prettier can't resolve php plugin * refactor: πŸ’‘ fix link in comments * refactor: πŸ’‘ match both .js and .mjs for jest target * Remove `require` * Add a comment --------- Co-authored-by: fisker Cheung <lionkay@gmail.com>
1 parent 977d3f6 commit 69a68d8

File tree

212 files changed

+34
-34
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

212 files changed

+34
-34
lines changed

β€Ž.eslintrc.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ overrides:
4747
- files: "**/*.cjs"
4848
parserOptions:
4949
sourceType: "script"
50-
- files: "tests/**/*.js"
50+
- files: "tests/**/*.mjs"
5151
globals:
5252
run_spec: true
53-
- files: "build/*.js"
53+
- files: "build/*.mjs"
5454
parserOptions:
5555
sourceType: module

β€Žbuild/rollup.config.js renamed to β€Žbuild/rollup.config.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import terser from "@rollup/plugin-terser";
1212
const getPath = (file) => url.fileURLToPath(new URL(file, import.meta.url));
1313

1414
export default {
15-
input: getPath("../src/index.js"),
15+
input: getPath("../src/index.mjs"),
1616
output: {
1717
file: "standalone.js",
1818
format: "umd",
@@ -32,10 +32,10 @@ export default {
3232
}),
3333
commonjs(),
3434
alias({
35-
entries: [{ find: "assert", replacement: getPath("./shims/assert.js") }],
35+
entries: [{ find: "assert", replacement: getPath("./shims/assert.mjs") }],
3636
}),
3737
inject({
38-
Buffer: getPath("./shims/buffer.js"),
38+
Buffer: getPath("./shims/buffer.mjs"),
3939
}),
4040
replace({
4141
preventAssignment: true,
File renamed without changes.
File renamed without changes.

β€Žjest.config.js renamed to β€Žjest.config.mjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ const RUN_STANDALONE_TESTS = Boolean(process.env.RUN_STANDALONE_TESTS);
66
export default {
77
// collectCoverage: ENABLE_COVERAGE,
88
collectCoverageFrom: [
9-
"<rootDir>/src/**/*.js",
9+
"<rootDir>/src/**/*.mjs",
1010
"!<rootDir>/node_modules/",
1111
"!<rootDir>/tests_config/",
1212
],
1313
runner: "jest-light-runner",
1414
transform: {},
15-
setupFiles: ["<rootDir>/tests_config/run_spec.js"],
16-
testRegex: "jsfmt\\.spec\\.js$|__tests__/.*\\.js$",
15+
setupFiles: ["<rootDir>/tests_config/run_spec.mjs"],
16+
// Matches `.js` file to prevent files use `.js` extension by mistake, https://github.com/prettier/plugin-php/pull/2247#discussion_r1331847801
17+
testRegex: "jsfmt\\.spec\\.m?js$|__tests__/.*\\.m?js$",
1718
snapshotSerializers: ["jest-snapshot-serializer-raw"],
1819
globals: {
1920
STANDALONE: RUN_STANDALONE_TESTS,

β€Žpackage.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"repository": "prettier/prettier-php",
66
"author": "Lucas Azzola <@azz>",
77
"license": "MIT",
8-
"type": "module",
98
"unpkg": "./standalone.js",
109
"browser": "./standalone.js",
1110
"exports": {
@@ -65,8 +64,8 @@
6564
"test:node": "jest",
6665
"test:standalone": "yarn run build && cross-env RUN_STANDALONE_TESTS=true yarn jest",
6766
"prepublishOnly": "yarn test",
68-
"prettier": "prettier --plugin=src/index.js --parser=php",
69-
"build": "rollup --config build/rollup.config.js",
67+
"prettier": "prettier --plugin=src/index.mjs --parser=php",
68+
"build": "rollup --config build/rollup.config.mjs",
7069
"debug": "node --inspect-brk node_modules/.bin/jest --runInBand"
7170
},
7271
"c8": {

β€Žsrc/clean.js renamed to β€Žsrc/clean.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { printNumber, normalizeMagicMethodName } from "./util.js";
1+
import { printNumber, normalizeMagicMethodName } from "./util.mjs";
22

33
const ignoredProperties = new Set([
44
"loc",

β€Žsrc/comments.js renamed to β€Žsrc/comments.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { util as prettierUtil, doc } from "prettier";
2-
import { isLookupNode } from "./util.js";
3-
import { locStart, locEnd } from "./loc.js";
2+
import { isLookupNode } from "./util.mjs";
3+
import { locStart, locEnd } from "./loc.mjs";
44

55
const {
66
addLeadingComment,
@@ -830,7 +830,7 @@ function printComment(path, options) {
830830
return options.printer.printComment(path, options);
831831
}
832832

833-
// https://github.com/prettier/prettier/blob/master/src/main/comments.js#L440
833+
// https://github.com/prettier/prettier/blob/6bff776efd0951b7812818d02d1cae3fda184737/src/main/comments/print.js#L119
834834
function printDanglingComments(path, options, sameIndent, filter) {
835835
const parts = [];
836836
const node = path.getValue();

β€Žsrc/index.js renamed to β€Žsrc/index.mjs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ import {
33
LINGUIST_LANGUAGES_PHP,
44
LINGUIST_LANGUAGES_HTML_PHP,
55
} from "./linguist-languages.cjs";
6-
import parse from "./parser.js";
7-
import print from "./printer.js";
8-
import clean from "./clean.js";
9-
import options from "./options.js";
6+
import parse from "./parser.mjs";
7+
import print from "./printer.mjs";
8+
import clean from "./clean.mjs";
9+
import options from "./options.mjs";
1010
import {
1111
handleOwnLineComment,
1212
handleEndOfLineComment,
1313
handleRemainingComment,
1414
getCommentChildNodes,
1515
canAttachComment,
1616
isBlockComment,
17-
} from "./comments.js";
18-
import { hasPragma, insertPragma } from "./pragma.js";
19-
import { locStart, locEnd } from "./loc.js";
17+
} from "./comments.mjs";
18+
import { hasPragma, insertPragma } from "./pragma.mjs";
19+
import { locStart, locEnd } from "./loc.mjs";
2020

2121
const { join, hardline } = doc.builders;
2222

File renamed without changes.

0 commit comments

Comments
Β (0)