2
0
Adam Shaw 5 жил өмнө
parent
commit
d2e561119d

+ 2 - 2
rollup.config.js

@@ -14,8 +14,8 @@ const buildDtsConfig = require('./scripts/lib/rollup-dts')
 
 
 module.exports = [
+  buildDtsConfig(),
   ...buildModuleConfigs(isDev),
   ...buildBundleConfigs(isDev),
-  ...buildTestConfigs(),
-  buildDtsConfig()
+  ...buildTestConfigs()
 ]

+ 6 - 3
scripts/lib/rollup-bundles.js

@@ -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')
@@ -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
         }
       }

+ 28 - 8
scripts/lib/rollup-dts.js

@@ -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
         }

+ 24 - 5
scripts/lib/rollup-modules.js

@@ -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
 }
 
 
@@ -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 : []),

+ 12 - 3
scripts/lib/rollup-tests.js

@@ -35,7 +35,6 @@ module.exports = function() {
   return configs
 }
 
-
 function buildConfig(options) {
   let nodeModulesDirs = [
     'packages/__tests__/node_modules',
@@ -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
         }
       },
@@ -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)

+ 11 - 1
scripts/lib/rollup-util.js

@@ -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 = /^~/
 
@@ -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)
 }