Skip to content

Commit

Permalink
rollup config
Browse files Browse the repository at this point in the history
  • Loading branch information
arshaw committed Apr 26, 2020
1 parent a8f4dfc commit d2e5611
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 22 deletions.
4 changes: 2 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const buildDtsConfig = require('./scripts/lib/rollup-dts')


module.exports = [
buildDtsConfig(),
...buildModuleConfigs(isDev),
...buildBundleConfigs(isDev),
...buildTestConfigs(),
buildDtsConfig()
...buildTestConfigs()
]
9 changes: 6 additions & 3 deletions scripts/lib/rollup-bundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const glob = require('glob')
const commonjs = require('rollup-plugin-commonjs')
const nodeResolve = require('rollup-plugin-node-resolve')
const postCss = require('rollup-plugin-postcss')
const { renderBanner, isRelPath, SOURCEMAP_PLUGINS, WATCH_OPTIONS, EXTERNAL_BROWSER_GLOBALS, TEMPLATE_PLUGIN, onwarn, isScssPath } = require('./rollup-util')
const { renderBanner, isRelPath, isNamedPkg, SOURCEMAP_PLUGINS, WATCH_OPTIONS, EXTERNAL_BROWSER_GLOBALS, TEMPLATE_PLUGIN, onwarn, isScssPath } = require('./rollup-util')
const { pkgStructs, pkgStructHash, getCorePkgStruct, getNonPremiumBundle } = require('./pkg-struct')
const alias = require('rollup-plugin-alias')
const replace = require('rollup-plugin-replace')
Expand Down Expand Up @@ -133,8 +133,11 @@ function buildNonBundleConfig(pkgStruct, bundleDistDir, isDev) {
resolveId(id) {
if (id === inputFile) { return inputFile }
if (id === 'tslib') { return { id, external: false } }
if (id === '@fullcalendar/core') { return { id: 'fullcalendar', external: true } } // TODO: shouldn't this be 'fullcalendar-scheduler' in some cases?
if (!isRelPath(id)) { return { id, external: true } }
if (
id === '@fullcalendar/core' ||
id === '@fullcalendar/preact'
) { return { id: 'fullcalendar', external: true } } // TODO: shouldn't this be 'fullcalendar-scheduler' in some cases?
if (isNamedPkg(id)) { return { id, external: true } }
return null
}
}
Expand Down
36 changes: 28 additions & 8 deletions scripts/lib/rollup-dts.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,55 @@
const dts = require('rollup-plugin-dts').default
const { isScssPath, isRelPath } = require('./rollup-util')
const { isScssPath, isNamedPkg } = require('./rollup-util')
const { pkgStructs } = require('./pkg-struct')
const { mapHashViaPair } = require('./util')
const { mapHashViaPair, copyFile } = require('./util')


// rollup-plugin-dts can't handle either of these
copyFile( // promise :(
'tmp/tsc-output/packages/preact/src/vdom.d.ts',
'packages/preact/dist/vdom.d.ts'
)
copyFile( // promise :(
'tmp/tsc-output/packages/core/src/vdom.d.ts',
'packages/core/dist/vdom.d.ts'
)


let hash = mapHashViaPair(pkgStructs, (pkgStruct) => [
pkgStruct.distDir, // the key. the [name] in entryFileNames
'./' + pkgStruct.tscMain + '.d.ts' // the value
])

module.exports = function() {
return {
input: mapHashViaPair(pkgStructs, (pkgStruct) => [
pkgStruct.distDir, // the key. the [name] in entryFileNames
'./' + pkgStruct.tscMain + '.d.ts' // the value
]),
input: hash,
output: {
format: 'es',
dir: '.',
entryFileNames: '[name]/main.d.ts'
},
plugins: [
{
resolveId(id) { // not DRY
if (id.match(/vdom$/)) {
return { id: './vdom', external: true }
}
}
},
dts(),
{
resolveId(id, source) {
if (isScssPath(id)) {
return false
}
if (!isRelPath(id)) {
if (isNamedPkg(id)) {
return { id, external: true }
}
return null
},
renderChunk(code, chunk) {
if (chunk.fileName === 'packages/core/dist/main.d.ts') {
return fixCode(code)
code = fixCode(code)
}
return code
}
Expand Down
29 changes: 24 additions & 5 deletions scripts/lib/rollup-modules.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
const path = require('path')
const { readFileSync } = require('fs')
const nodeResolve = require('rollup-plugin-node-resolve')
const { renderBanner, isRelPath, isScssPath, TEMPLATE_PLUGIN, SOURCEMAP_PLUGINS, WATCH_OPTIONS, onwarn } = require('./rollup-util')
const { pkgStructs, getCorePkgStruct } = require('./pkg-struct')
const { renderBanner, isRelPath, isNamedPkg, isScssPath, TEMPLATE_PLUGIN, SOURCEMAP_PLUGINS, WATCH_OPTIONS, onwarn } = require('./rollup-util')
const { pkgStructs } = require('./pkg-struct')
const { copyFile } = require('./util')


// needed to have this in separate file because rollup wasn't understanding that it has side effects and needed to go before the @fullcalendar/core import
// added bonuses:
// - the import statement doesn't import any vars, which will maybe hint to the build env that there are side effects
// - rollup-plugin-dts needed to handle the .d.ts files separately anyway
copyFile( // promise :(
'tmp/tsc-output/packages/preact/src/vdom.js',
'packages/preact/dist/vdom.js'
)


module.exports = function(isDev) {
return pkgStructs.filter((pkgStruct) => !pkgStruct.isBundle)
let configs = pkgStructs.filter((pkgStruct) => !pkgStruct.isBundle)
.map((pkgStruct) => buildPkgConfig(pkgStruct, isDev))

return configs
}


Expand All @@ -23,9 +35,16 @@ function buildPkgConfig(pkgStruct, isDev) {
sourcemap: isDev
},
external(id) {
return !isRelPath(id)
return isNamedPkg(id)
},
plugins: [
{
resolveId(id, source) {
if (id.match(/vdom$/) && source.match('packages/preact')) {
return { id, external: true }
}
}
},
nodeResolve(),
TEMPLATE_PLUGIN,
...(isDev ? SOURCEMAP_PLUGINS : []),
Expand Down
15 changes: 12 additions & 3 deletions scripts/lib/rollup-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ module.exports = function() {
return configs
}


function buildConfig(options) {
let nodeModulesDirs = [
'packages/__tests__/node_modules',
Expand All @@ -51,13 +50,23 @@ function buildConfig(options) {
},
plugins: [
{
resolveId(id, importer) { // TODO: not really DRY
resolveId(id, importer) {

// contrib files are not processed by tsc and not in tmp/
if (isRelPath(id)) {
let m = id.match(/(packages-contrib\/.*)$/)
if (m) {
return { id: m[1].replace('/src/', '/dist/') + '.js' }
}
}

if (isStylePath(id) && isRelPath(id) && importer.match('/tmp/tsc-output/')) {
let resourcePath = importer.replace('/tmp/tsc-output/', '/')
resourcePath = path.dirname(resourcePath)
resourcePath = path.join(resourcePath, id)
return { id: resourcePath, external: false }
}

return null
}
},
Expand Down Expand Up @@ -85,7 +94,7 @@ function buildConfig(options) {
}
}),
commonjs({
// also for react(-dom) hack, ALSO IN rollup-bundle.js
// for react(-dom) hack, ALSO IN rollup-bundle.js
namedExports: {
'react': Object.keys(react),
'react-dom': Object.keys(reactDom)
Expand Down
12 changes: 11 additions & 1 deletion scripts/lib/rollup-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ exports.renderBanner = handleBars.compile(
)


const REL_PATH_RE = /^[/.]/
const REL_PATH_RE = /^\./
const SCSS_PATH_RE = /\.scss$/i
const TILDE_PATH_RE = /^~/

Expand All @@ -73,6 +73,16 @@ exports.isRelPath = function(path) {
}


exports.isAbsPath = function(path) { // not x-OS-friendly
return /^\//.test(path)
}


exports.isNamedPkg = function(path) {
return !exports.isRelPath(path) && !exports.isAbsPath(path)
}


exports.isScssPath = function(path) {
return SCSS_PATH_RE.test(path)
}
Expand Down

0 comments on commit d2e5611

Please sign in to comment.