Skip to content

Commit

Permalink
Generate plugin list file (#4725)
Browse files Browse the repository at this point in the history
* Generate plugin list file

Removes the importing of all plugins in src/util/resolveConfig to avoid importing CSS.
Import the built plugin list file instead.

* Use `process.cwd()` instead of `__dirname` to resolve path

Co-authored-by: Federico Ciardi <fed.ciardi@gmail.com>

* Import core plugin list in resolveConfig test

* Generate plugin list prebabelify and on install

* Move generation from install to postinstall

Co-authored-by: Federico Ciardi <fed.ciardi@gmail.com>

Co-authored-by: Federico Ciardi <fed.ciardi@gmail.com>
  • Loading branch information
sachinraja and fedeci committed Jun 23, 2021
1 parent 973d53d commit c0ee520
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 19 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Expand Up @@ -4,3 +4,4 @@
/peers
/tests/fixtures/cli-utils.js
/stubs/*
/src/corePluginList.js
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -15,3 +15,6 @@ yarn-error.log

# Perf related files
isolate*.log

# Generated files
/src/corePluginList.js
35 changes: 23 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Expand Up @@ -18,18 +18,20 @@
"David Hemphill <davidlee.hemphill@gmail.com>"
],
"scripts": {
"prebabelify": "rimraf lib",
"prebabelify": "npm run generate:plugin-list && rimraf lib",
"babelify": "babel src --out-dir lib --copy-files",
"postbabelify": "ncc build lib/cli-peer-dependencies.js -o peers",
"rebuild-fixtures": "npm run babelify && babel-node scripts/rebuildFixtures.js",
"prepublishOnly": "npm install --force && npm run babelify && babel-node scripts/build.js && node scripts/build-plugins.js",
"style": "eslint .",
"test": "cross-env TAILWIND_MODE=build jest",
"test:integrations": "npm run test --prefix ./integrations",
"postinstall": "npm run generate:plugin-list",
"install:integrations": "node scripts/install-integrations.js",
"posttest": "npm run style",
"compat": "node scripts/compat.js --prepare",
"compat:restore": "node scripts/compat.js --restore"
"compat:restore": "node scripts/compat.js --restore",
"generate:plugin-list": "babel-node scripts/create-plugin-list.js"
},
"files": [
"dist/*.css",
Expand Down
10 changes: 10 additions & 0 deletions scripts/create-plugin-list.js
@@ -0,0 +1,10 @@
import * as corePlugins from '../src/plugins'
import fs from 'fs'
import path from 'path'

const corePluginList = Object.keys(corePlugins)

fs.writeFileSync(
path.join(process.cwd(), 'src', 'corePluginList.js'),
`export default ${JSON.stringify(corePluginList)}`
)
4 changes: 2 additions & 2 deletions src/util/resolveConfig.js
Expand Up @@ -10,7 +10,7 @@ import toPath from 'lodash/toPath'
import head from 'lodash/head'
import isPlainObject from 'lodash/isPlainObject'
import negateValue from './negateValue'
import * as corePlugins from '../plugins'
import corePluginList from '../corePluginList'
import configurePlugins from './configurePlugins'
import defaultConfig from '../../stubs/defaultConfig.stub'
import colors from '../../colors'
Expand Down Expand Up @@ -243,7 +243,7 @@ function resolveCorePlugins(corePluginConfigs) {
return corePluginConfig({ corePlugins: resolved })
}
return configurePlugins(corePluginConfig, resolved)
}, Object.keys(corePlugins))
}, corePluginList)

return result
}
Expand Down
4 changes: 1 addition & 3 deletions tests/resolveConfig.test.js
@@ -1,7 +1,5 @@
import * as corePlugins from '../src/plugins'
import resolveConfig from '../src/util/resolveConfig'

const corePluginList = Object.keys(corePlugins)
import corePluginList from '../src/corePluginList'

test('prefix key overrides default prefix', () => {
const userConfig = {
Expand Down

1 comment on commit c0ee520

@Cynthiam13
Copy link

Choose a reason for hiding this comment

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

Simple File List is a free plugin that is great for when you need to provide a list of files, either publicly available or private to logged-in users.

Please sign in to comment.