Skip to content

Automatically load plugins from package.json#3624

Merged
azz merged 6 commits intoprettier:masterfrom
azz:autoload-plugins
Jan 5, 2018
Merged

Automatically load plugins from package.json#3624
azz merged 6 commits intoprettier:masterfrom
azz:autoload-plugins

Conversation

@azz
Copy link
Copy Markdown
Member

@azz azz commented Jan 1, 2018

Automatically loads plugins with the name @prettier/plugin-* or prettier-plugin-* from the nearest package.json up the file system tree.

@azz
Copy link
Copy Markdown
Member Author

azz commented Jan 3, 2018

Unexpected error:

 PASS  tests/array_spread/jsfmt.spec.js (5.972s)
<--- Last few GCs --->
  265556 ms: Scavenge 1379.9 (1457.9) -> 1379.9 (1457.9) MB, 1.3 / 0 ms (+ 1.0 ms in 2 steps since last GC) [allocation failure] [incremental marking delaying mark-sweep].
  267417 ms: Mark-sweep 1379.9 (1457.9) -> 1379.5 (1457.9) MB, 1861.4 / 0 ms (+ 2.2 ms in 4 steps since start of marking, biggest step 1.2 ms) [last resort gc].
  269148 ms: Mark-sweep 1379.5 (1457.9) -> 1311.8 (1457.9) MB, 1730.8 / 0 ms [last resort gc].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x10db7f037399 <JS Object>
    1: b(aka b) [/home/travis/build/prettier/prettier/node_modules/flow-parser/flow_parser.js:425] [pc=0x1f2183c69b34] (this=0x10db7f004131 <undefined>,a=0x1b6f7df58ca1 <JS Function k (SharedFunctionInfo 0x29fbcf413b69)>,b=0x1b6f7df58ce9 <JS Array[3]>)
    2: lA(aka lA) [/home/travis/build/prettier/prettier/node_modules/flow-parser/flow_parser.js:539] [pc=0x1f2183cc1935] (this=0x10db7f004131 <u...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory
Aborted (core dumped)

@ikatyang
Copy link
Copy Markdown
Member

ikatyang commented Jan 3, 2018

I can reproduce the error locally but only with --runInBand. 🤔

Comment thread yarn.lock Outdated
find-up "^2.0.0"
read-pkg "^2.0.0"

read-pkg-up@^3.0.0:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after yarn.. 😂

image

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upgraded yarn - problem went away. Hopefully the last time 😭

Comment thread src/common/support.js Outdated
}

const plugins = loadPlugins();
const plugins = loadPlugins(opts);
Copy link
Copy Markdown
Collaborator

@duailibe duailibe Jan 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This opts is not the same options (i.e. the context) we're passing around in other places. This is type {showUnreleased: boolean}.

This must have gotten mixed up when I fixed merge conflicts of the PR

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of - in https://github.com/prettier/prettier/pull/3536/files#diff-7ac67a485f01c26ab36e763ce88748a5 I switched it to use options but it wasn't required. Added plugins to the options that can be passed here.

@azz
Copy link
Copy Markdown
Member Author

azz commented Jan 4, 2018

More insights into the Jest crash:

Security context: 0x171c1dba5739 <JSObject>
    2: replace(this=0x1de250589549 <String[6]: ~2.6.1>,0xe3fae98b291 <JSRegExp <String[407]: (\s*)((?:<|>)?=?)\s*([v=\s]*([0-9]+)\.([0-9]+)\.([0-9]+)(?:-?((?:[0-9]+|\d*[a-zA-Z-][a-zA-Z0-9-]*)(?:\.(?:[0-9]+|\d*[a-zA-Z-][a-zA-Z0-9-]*))*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?|[v=\s]*(0|[1-9]\d*|x|X|\*)(?:\.(0|[1-9]\d*|x|X|\*)(?:\.(0|[1-9]\d*|x|X|\*)(?:(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][a-zA-Z0-9...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [node]
 2: 0x11ef43c [node]
 3: v8::Utils::ReportOOMFailure(char const*, bool) [node]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node]
 5: v8::internal::Factory::NewCode(v8::internal::CodeDesc const&, unsigned int, v8::internal::Handle<v8::internal::Object>, bool, int) [node]
 6: v8::internal::RegExpMacroAssemblerX64::GetCode(v8::internal::Handle<v8::internal::String>) [node]
 7: v8::internal::RegExpCompiler::Assemble(v8::internal::RegExpMacroAssembler*, v8::internal::RegExpNode*, int, v8::internal::Handle<v8::internal::String>) [node]
 8: v8::internal::RegExpEngine::Compile(v8::internal::Isolate*, v8::internal::Zone*, v8::internal::RegExpCompileData*, v8::base::Flags<v8::internal::JSRegExp::Flag, int>, v8::internal::Handle<v8::internal::String>, v8::internal::Handle<v8::internal::String>, bool) [node]
 9: v8::internal::RegExpImpl::CompileIrregexp(v8::internal::Handle<v8::internal::JSRegExp>, v8::internal::Handle<v8::internal::String>, bool) [node]
10: v8::internal::RegExpImpl::IrregexpPrepare(v8::internal::Handle<v8::internal::JSRegExp>, v8::internal::Handle<v8::internal::String>) [node]
11: 0x10b3cbb [node]
12: 0x10b5038 [node]
13: v8::internal::Runtime_RegExpReplace(int, v8::internal::Object**, v8::internal::Isolate*) [node]
14: 0x191717e842fd
Aborted (core dumped)

@azz
Copy link
Copy Markdown
Member Author

azz commented Jan 4, 2018

--runInBand is running really slow on my machine when it approaches the memory limit. Based on the intermittent failures in CI recently, I think there's an outstanding leak and this PR is somehow pushing it over the edge.

Not really sure how to diagnose this further. I'll try attaching a profiler to it soon.

@azz
Copy link
Copy Markdown
Member Author

azz commented Jan 4, 2018

Maybe a leak in loadJsonFile, readPkg or readPkgUp?

image

@azz
Copy link
Copy Markdown
Member Author

azz commented Jan 4, 2018

This is crazy - If I comment out require("read-pkg-up"), everything works fine.

@azz
Copy link
Copy Markdown
Member Author

azz commented Jan 4, 2018

Bisecting down the require tree, isolated it to graceful-fs.

Comment thread jest.config.js
"<rootDir>/src/deprecated.js"
],
moduleNameMapper: {
"graceful-fs": "<rootDir>/tests_config/fs.js"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this works, maybe add a comment explaining why we do this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I want to test it out in CI, and maybe do the same thing with the Rollup builds.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually not in the rollup build - see jestjs/jest#2179 (comment)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the dev build, but the production build is still broken (because graceful-fs will be bundled in). Should I remap graceful-fs for the Rollup build too?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could put it in third-party.js?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so because we're not requiring it, load-json-file is

replace({
"#!/usr/bin/env node": "",
// See comment in jest.config.js
"require('graceful-fs')": "require('fs')"
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried doing this with rollup-plugin-alias, but couldn't get it working.

@azz
Copy link
Copy Markdown
Member Author

azz commented Jan 4, 2018

Build is green - ready for review 😄

Comment thread src/common/support.js
opts = Object.assign(
{
plugins: [],
pluginsLoaded: false,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should write some docs for these options.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still somewhat intentionally undocumented as it is unreleased.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@azz You could write it up in an HTML comment, then remove the <!-- and --> when the update is released.

@azz azz merged commit e5d6a47 into prettier:master Jan 5, 2018
@azz azz deleted the autoload-plugins branch January 5, 2018 10:09
@ikatyang
Copy link
Copy Markdown
Member

ikatyang commented Jan 5, 2018

It seems this PR introduced an Uncaught TypeError: process.binding is not a function error on the playground.

@lock lock Bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jan 18, 2019
@lock lock Bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants