@vitus-labs/tools-rollup 0.41.0 → 0.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/bin/run-build.js +1 -1
  2. package/{typings → global}/index.d.ts +0 -0
  3. package/lib/config/baseConfig.js +2 -0
  4. package/lib/config/baseConfig.js.map +1 -1
  5. package/lib/config/index.js +9 -5
  6. package/lib/config/index.js.map +1 -1
  7. package/lib/declarations/index.js +3 -0
  8. package/lib/declarations/index.js.map +1 -0
  9. package/lib/index.js +1 -1
  10. package/lib/index.js.map +1 -1
  11. package/lib/rollup/config.js +130 -0
  12. package/lib/rollup/config.js.map +1 -0
  13. package/lib/rollup/createBuildPipeline.js +138 -0
  14. package/lib/rollup/createBuildPipeline.js.map +1 -0
  15. package/lib/rollup/index.js +11 -0
  16. package/lib/rollup/index.js.map +1 -0
  17. package/lib/scripts/build.js +119 -59
  18. package/lib/scripts/build.js.map +1 -1
  19. package/lib/types/config/baseConfig.d.ts +1 -0
  20. package/lib/types/config/index.d.ts +4 -3
  21. package/lib/types/declarations/index.d.ts +17 -0
  22. package/lib/types/{config/rollup.d.ts → rollup/config.d.ts} +9 -7
  23. package/lib/types/rollup/createBuildPipeline.d.ts +2 -0
  24. package/lib/types/rollup/index.d.ts +3 -0
  25. package/package.json +9 -5
  26. package/src/config/{baseConfig.js → baseConfig.ts} +2 -1
  27. package/src/config/index.ts +10 -0
  28. package/src/index.ts +3 -0
  29. package/src/{config/rollup.js → rollup/config.ts} +43 -48
  30. package/src/{scripts/utils.js → rollup/createBuildPipeline.ts} +21 -18
  31. package/src/rollup/index.ts +4 -0
  32. package/src/scripts/{build.js → build.ts} +21 -33
  33. package/tsconfig.json +25 -0
  34. package/tsconfig.tsbuildinfo +1 -0
  35. package/lib/config/rollup.js +0 -129
  36. package/lib/config/rollup.js.map +0 -1
  37. package/lib/scripts/utils.js +0 -138
  38. package/lib/scripts/utils.js.map +0 -1
  39. package/lib/types/scripts/utils.d.ts +0 -2
  40. package/lib/types/utils.d.ts +0 -5
  41. package/lib/utils.js +0 -106
  42. package/lib/utils.js.map +0 -1
  43. package/src/config/index.js +0 -4
  44. package/src/index.js +0 -3
  45. package/src/utils.js +0 -129
@@ -0,0 +1,17 @@
1
+ export {};
2
+ declare global {
3
+ const __BROWSER__: true;
4
+ const __WEB__: true;
5
+ const __NATIVE__: true;
6
+ const __NODE__: true;
7
+ const __CLIENT__: true;
8
+ }
9
+ declare global {
10
+ interface Window {
11
+ __BROWSER__: true;
12
+ __WEB__: true;
13
+ __NATIVE__: true;
14
+ __NODE__: true;
15
+ __CLIENT__: true;
16
+ }
17
+ }
@@ -1,10 +1,6 @@
1
- declare const rollupConfig: ({ file, format, env, types, platform }: {
2
- file: any;
3
- format: any;
4
- env: any;
5
- types: any;
6
- platform: any;
7
- }) => {
1
+ declare const rollupConfig: ({ file, format, env, types, platform, }: Record<string, any>) => {
2
+ makeAbsoluteExternalsRelative: boolean;
3
+ preserveEntrySignatures: string;
8
4
  input: any;
9
5
  output: {
10
6
  file: any;
@@ -13,6 +9,12 @@ declare const rollupConfig: ({ file, format, env, types, platform }: {
13
9
  sourcemap: boolean;
14
10
  exports: string | undefined;
15
11
  name: any;
12
+ esModule: boolean;
13
+ generatedCode: {
14
+ reservedNamesAsProps: boolean;
15
+ };
16
+ interop: string;
17
+ systemNullSetters: boolean;
16
18
  };
17
19
  external: any;
18
20
  plugins: import("rollup").Plugin[];
@@ -0,0 +1,2 @@
1
+ declare const createBuildPipeline: () => Record<string, any>[];
2
+ export default createBuildPipeline;
@@ -0,0 +1,3 @@
1
+ import config from './config';
2
+ import createBuildPipeline from './createBuildPipeline';
3
+ export { createBuildPipeline, config };
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@vitus-labs/tools-rollup",
3
- "version": "0.41.0",
3
+ "version": "0.42.0",
4
4
  "license": "MIT",
5
5
  "author": "Vit Bokisch <vit@bokisch.com>",
6
6
  "maintainers": [
7
7
  "Vit Bokisch <vit@bokisch.com>"
8
8
  ],
9
- "main": "./index.js",
10
- "types": "typings/index.d.ts",
9
+ "main": "lib/index.js",
10
+ "types": "lib/typings/index.d.ts",
11
11
  "bin": {
12
12
  "vl_build": "bin/run-build.js",
13
13
  "vl_build-watch": "bin/run-watch.js"
@@ -15,16 +15,20 @@
15
15
  "engines": {
16
16
  "node": ">= 14"
17
17
  },
18
+ "scripts": {
19
+ "prepublish": "yarn build",
20
+ "build": "tsc"
21
+ },
18
22
  "publishConfig": {
19
23
  "access": "public"
20
24
  },
21
25
  "dependencies": {
22
26
  "@microsoft/api-extractor": "^7.33.7",
23
- "@rollup/plugin-babel": "^6.0.3",
24
27
  "@rollup/plugin-node-resolve": "^15.0.1",
25
28
  "@rollup/plugin-replace": "^5.0.2",
26
29
  "@rollup/plugin-terser": "^0.3.0",
27
30
  "@types/node": "^18.11.18",
31
+ "@vitus-labs/tools-core": "0.42.0",
28
32
  "chalk": "^4.1.2",
29
33
  "find-up": "^5.0.0",
30
34
  "lodash.merge": "^4.6.2",
@@ -38,5 +42,5 @@
38
42
  "tslib": "^2.4.1",
39
43
  "ttypescript": "^1.5.15"
40
44
  },
41
- "gitHead": "ca8e6a7725965352158bc5e1de1b79c6d8f15319"
45
+ "gitHead": "e271a9b9bd8bb25150fdff84ac86b4f30fad55a9"
42
46
  }
@@ -1,8 +1,9 @@
1
- module.exports = {
1
+ export default {
2
2
  sourceDir: 'src',
3
3
  outputDir: 'lib',
4
4
  typesDir: 'lib/types',
5
5
  typescript: true,
6
+ esModulesOnly: false,
6
7
  replaceGlobals: true,
7
8
  visualise: {
8
9
  template: 'network',
@@ -0,0 +1,10 @@
1
+ import { loadVLToolsConfig, PKG } from '@vitus-labs/tools-core'
2
+ import baseConfig from './baseConfig'
3
+
4
+ const CONFIG_KEY = 'rollup'
5
+
6
+ const CONFIG = loadVLToolsConfig(CONFIG_KEY).merge(baseConfig).config
7
+
8
+ const PLATFORMS = ['browser', 'node', 'web', 'native']
9
+
10
+ export { CONFIG, PKG, PLATFORMS }
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ import runBuild from './scripts/build'
2
+
3
+ export default runBuild
@@ -1,22 +1,19 @@
1
- const typescript = require('rollup-plugin-typescript2')
2
- const ttypescript = require('ttypescript')
3
- const pathsTransformer = require('ts-transform-paths').default
4
- const { apiExtractor } = require('rollup-plugin-api-extractor')
5
- const { nodeResolve } = require('@rollup/plugin-node-resolve')
6
- const filesize = require('rollup-plugin-filesize')
7
- const { visualizer } = require('rollup-plugin-visualizer')
8
- const replace = require('@rollup/plugin-replace')
9
- const { terser } = require('@rollup/plugin-terser')
10
- // const babel = require('@rollup/plugin-babel')
11
- const baseConfig = require('./baseConfig')
12
- const { PKG, loadConfig, swapGlobals } = require('../utils')
13
-
14
- const CONFIG = loadConfig(baseConfig)
1
+ import { swapGlobals } from '@vitus-labs/tools-core'
2
+ import typescript from 'rollup-plugin-typescript2'
3
+ import ttypescript from 'ttypescript'
4
+ import pathsTransformer from 'ts-transform-paths'
5
+ import { apiExtractor } from 'rollup-plugin-api-extractor'
6
+ import { nodeResolve } from '@rollup/plugin-node-resolve'
7
+ import filesize from 'rollup-plugin-filesize'
8
+ import { visualizer } from 'rollup-plugin-visualizer'
9
+ import replace from '@rollup/plugin-replace'
10
+ import terser from '@rollup/plugin-terser'
11
+ import { CONFIG, PKG, PLATFORMS } from '../config'
15
12
 
16
13
  const defineExtensions = (platform) => {
17
- const platformExtensions = []
14
+ const platformExtensions: string[] = []
18
15
 
19
- if (['browser', 'node', 'web', 'native'].includes(platform)) {
16
+ if (PLATFORMS.includes(platform)) {
20
17
  CONFIG.extensions.forEach((item) => {
21
18
  platformExtensions.push(`.${platform}${item}`)
22
19
  })
@@ -27,38 +24,30 @@ const defineExtensions = (platform) => {
27
24
 
28
25
  const loadPlugins = ({ env, platform, types, file }) => {
29
26
  const extensions = defineExtensions(platform)
27
+ const plugins = [nodeResolve({ extensions, browser: platform === 'browser' })]
30
28
 
31
- // const babelConfig = {
32
- // extensions,
33
- // include: [CONFIG.sourceDir],
34
- // exclude: CONFIG.exclude,
35
- // babelHelpers: 'bundled',
36
- // }
37
-
38
- const tsConfig = {
39
- typescript: ttypescript,
40
- transformers: [(service) => pathsTransformer(service)],
41
- exclude: CONFIG.exclude,
42
- useTsconfigDeclarationDir: true,
43
- clean: true,
44
- tsconfigDefaults: {
29
+ if (CONFIG.typescript) {
30
+ const tsConfig: Record<string, any> = {
31
+ typescript: ttypescript,
32
+ transformers: [(service) => pathsTransformer(service)],
45
33
  exclude: CONFIG.exclude,
46
- include: CONFIG.include,
47
- compilerOptions: {
48
- types: ['@vitus-labs/tools-rollup'],
34
+ useTsconfigDeclarationDir: true,
35
+ clean: true,
36
+ tsconfigDefaults: {
37
+ exclude: CONFIG.exclude,
38
+ include: CONFIG.include,
39
+ compilerOptions: {
40
+ types: ['@vitus-labs/tools-rollup'],
41
+ },
49
42
  },
50
- },
51
- }
52
-
53
- if (types) {
54
- tsConfig.tsconfigDefaults.compilerOptions.declarationMap = types
55
- tsConfig.tsconfigDefaults.compilerOptions.declaration = types
56
- tsConfig.tsconfigDefaults.compilerOptions.declarationDir = CONFIG.typesDir
57
- }
43
+ }
58
44
 
59
- const plugins = [nodeResolve({ extensions, browser: platform === 'browser' })]
45
+ if (types) {
46
+ tsConfig.tsconfigDefaults.compilerOptions.declarationMap = types
47
+ tsConfig.tsconfigDefaults.compilerOptions.declaration = types
48
+ tsConfig.tsconfigDefaults.compilerOptions.declarationDir = CONFIG.typesDir
49
+ }
60
50
 
61
- if (CONFIG.typescript) {
62
51
  plugins.push(typescript(tsConfig))
63
52
 
64
53
  if (types) {
@@ -66,10 +55,11 @@ const loadPlugins = ({ env, platform, types, file }) => {
66
55
  apiExtractor({
67
56
  cleanUpRollup: true,
68
57
  configuration: {
69
- mainEntryPointFilePath: `${CONFIG.typesDir}/index.d.ts`,
58
+ mainEntryPointFilePath: `<projectFolder>/${CONFIG.typesDir}/index.d.ts`,
70
59
  projectFolder: process.cwd(),
71
60
  compiler: {
72
61
  tsconfigFilePath: '<projectFolder>/tsconfig.json',
62
+ skipLibCheck: true,
73
63
  },
74
64
  dtsRollup: {
75
65
  enabled: true,
@@ -100,9 +90,8 @@ const loadPlugins = ({ env, platform, types, file }) => {
100
90
  plugins.push(replace({ preventAssignment: true, values: replaceOptions }))
101
91
  }
102
92
 
103
- // plugins.push(babel(babelConfig))
104
-
105
93
  // generate visualised graphs in dist folder
94
+
106
95
  if (CONFIG.visualise) {
107
96
  const filePath = file.split('/')
108
97
  const fileName = filePath.pop()
@@ -130,7 +119,13 @@ const loadPlugins = ({ env, platform, types, file }) => {
130
119
  return plugins
131
120
  }
132
121
 
133
- const rollupConfig = ({ file, format, env, types, platform }) => {
122
+ const rollupConfig = ({
123
+ file,
124
+ format,
125
+ env,
126
+ types,
127
+ platform,
128
+ }: Record<string, any>) => {
134
129
  const plugins = loadPlugins({ file, env, types, platform })
135
130
 
136
131
  const buildOutput = {
@@ -158,4 +153,4 @@ const rollupConfig = ({ file, format, env, types, platform }) => {
158
153
  return buildOutput
159
154
  }
160
155
 
161
- module.exports = rollupConfig
156
+ export default rollupConfig
@@ -1,12 +1,14 @@
1
- const { PKG } = require('../utils')
1
+ import { PKG, CONFIG } from '../config'
2
2
 
3
+ const isESMModule = PKG.type === 'module'
4
+ const { esModulesOnly } = CONFIG
3
5
  const shouldBuildNative = PKG['react-native'] !== PKG.module
4
6
  const shouldGenerateTypes = !!(PKG.types || PKG.typings)
5
7
 
6
8
  const hasDifferentBrowserBuild = (type) => {
7
9
  if (!PKG.browser) return false
8
10
 
9
- return Object.entries(PKG.browser).some(([key, value]) => {
11
+ return Object.entries(PKG.browser).some(([key, value]: [string, string]) => {
10
12
  const source = key.substring(2)
11
13
  const output = value.substring(2)
12
14
 
@@ -16,7 +18,7 @@ const hasDifferentBrowserBuild = (type) => {
16
18
 
17
19
  const BASE_VARIANTS = {
18
20
  main: {
19
- format: 'cjs',
21
+ format: esModulesOnly ? 'es' : 'cjs',
20
22
  env: 'development',
21
23
  platform: 'universal',
22
24
  },
@@ -35,40 +37,40 @@ const BASE_VARIANTS = {
35
37
  }
36
38
 
37
39
  const getExportsOptions = () => {
38
- const exportsOptions = PKG['exports']
40
+ const exportsOptions = PKG.exports
39
41
 
40
42
  if (!exportsOptions) return []
41
43
 
42
44
  if (typeof exportsOptions === 'string') {
43
45
  return [
44
46
  {
45
- file: PKG['exports'],
46
- ...BASE_VARIANTS['module'],
47
+ file: PKG.exports,
48
+ ...BASE_VARIANTS.module,
47
49
  },
48
50
  ]
49
51
  }
50
52
 
51
53
  if (typeof exportsOptions === 'object') {
52
- const result = []
54
+ const result: Record<string, any>[] = []
53
55
 
54
56
  if (exportsOptions.import) {
55
57
  result.push({
56
58
  file: exportsOptions.import,
57
- ...BASE_VARIANTS['module'],
59
+ ...BASE_VARIANTS.module,
58
60
  })
59
61
  }
60
62
 
61
63
  if (exportsOptions.require) {
62
64
  result.push({
63
65
  file: exportsOptions.require,
64
- ...BASE_VARIANTS['main'],
66
+ ...BASE_VARIANTS.main,
65
67
  })
66
68
  }
67
69
 
68
70
  if (exportsOptions.node) {
69
71
  result.push({
70
72
  file: exportsOptions.node,
71
- ...BASE_VARIANTS['module'],
73
+ ...BASE_VARIANTS.module,
72
74
  platform: 'node',
73
75
  })
74
76
  }
@@ -76,7 +78,7 @@ const getExportsOptions = () => {
76
78
  if (exportsOptions.default) {
77
79
  result.push({
78
80
  file: exportsOptions.default,
79
- ...BASE_VARIANTS['module'],
81
+ ...BASE_VARIANTS.module,
80
82
  })
81
83
  }
82
84
 
@@ -87,10 +89,9 @@ const getExportsOptions = () => {
87
89
  }
88
90
 
89
91
  const createBasicBuildVariants = () => {
90
- const isModule = PKG['type'] === 'module'
91
- let result = []
92
+ let result: Record<string, any>[] = []
92
93
 
93
- if (isModule) result = [...getExportsOptions()]
94
+ if (isESMModule) result = [...getExportsOptions()]
94
95
 
95
96
  Object.keys(BASE_VARIANTS).forEach((key) => {
96
97
  const PKGOutDir = PKG[key]
@@ -108,7 +109,9 @@ const createBasicBuildVariants = () => {
108
109
  if (shouldBuildNative) {
109
110
  add()
110
111
  }
111
- } else if (hasBrowserBuild) {
112
+ }
113
+
114
+ if (hasBrowserBuild) {
112
115
  // if has a different browser build, set default platform to node
113
116
  // as there is going to be created a separate browser build as well
114
117
  add({ platform: 'node' })
@@ -122,10 +125,10 @@ const createBasicBuildVariants = () => {
122
125
  }
123
126
 
124
127
  const createBrowserBuildVariants = () => {
125
- const result = []
128
+ const result: Record<string, any>[] = []
126
129
  if (!PKG.browser) return result
127
130
 
128
- Object.entries(PKG.browser).forEach(([key, value]) => {
131
+ Object.entries(PKG.browser).forEach(([key, value]: [string, string]) => {
129
132
  const source = key.substring(2) // strip './' from the beginning of path
130
133
  const output = value.substring(2) // strip './' from the beginning of path
131
134
 
@@ -155,4 +158,4 @@ const createBuildPipeline = () => {
155
158
  return result
156
159
  }
157
160
 
158
- module.exports = createBuildPipeline
161
+ export default createBuildPipeline
@@ -0,0 +1,4 @@
1
+ import config from './config'
2
+ import createBuildPipeline from './createBuildPipeline'
3
+
4
+ export { createBuildPipeline, config }
@@ -1,17 +1,20 @@
1
1
  /* eslint-disable @typescript-eslint/no-var-requires */
2
- const chalk = require('chalk')
3
- const rimraf = require('rimraf')
4
- const rollup = require('rollup')
5
- const { rollupConfig, baseConfig } = require('../config')
6
- const { loadConfig } = require('../utils')
7
- const createBuildPipeline = require('./utils')
2
+ import chalk from 'chalk'
3
+ import rimraf from 'rimraf'
4
+ import rollup from 'rollup'
5
+ import { CONFIG } from '../config'
6
+ import { config as rollupConfig, createBuildPipeline } from '../rollup'
8
7
 
9
8
  const { log } = console
10
- const CONFIG = loadConfig(baseConfig)
11
9
  const allBuilds = createBuildPipeline()
12
- // const allBuilds = allBuildOptions.map((item) => rollupConfig(item)).flat()
13
10
  const allBuildsCount = allBuilds.length
14
11
 
12
+ const MODULE_TYPES = {
13
+ cjs: 'CommonJS',
14
+ es: 'ES Module',
15
+ umd: 'UMD module',
16
+ }
17
+
15
18
  // --------------------------------------------------------
16
19
  // BUILD rollup
17
20
  // --------------------------------------------------------
@@ -29,32 +32,17 @@ const createBuilds = async () => {
29
32
 
30
33
  // serialize builds
31
34
  allBuilds.forEach((item, i) => {
32
- const buildOptions = rollupConfig(item)
33
-
34
- // it might be an array for such a cases like typescript optimization file
35
- // which we want to do in one iteration only
36
- if (Array.isArray(buildOptions)) {
37
- const [buildConfig, typescriptConfig] = buildOptions
38
-
39
- const { output, ...input } = buildConfig
40
- const { output: tsOutput, ...tsInput } = typescriptConfig
35
+ const { output, ...input } = rollupConfig(item)
36
+ const type = output.format
41
37
 
42
- p = p.then(() => {
43
- log(chalk.green(`🚧 Creating a build ${i + 1}/${allBuildsCount}`))
44
- return build({ inputOptions: input, outputOptions: output })
45
- })
46
-
47
- p = p.then(() =>
48
- build({ inputOptions: tsInput, outputOptions: tsOutput })
38
+ p = p.then(() => {
39
+ log(
40
+ chalk.green(`🚧 Creating a build ${i + 1}/${allBuildsCount}`),
41
+ chalk.gray(`(format: ${MODULE_TYPES[type]})`)
49
42
  )
50
- } else {
51
- const { output, ...input } = buildOptions
52
-
53
- p = p.then(() => {
54
- log(chalk.green(`🚧 Creating a build ${i + 1}/${allBuildsCount}`))
55
- return build({ inputOptions: input, outputOptions: output })
56
- })
57
- }
43
+
44
+ return build({ inputOptions: input, outputOptions: output })
45
+ })
58
46
  })
59
47
 
60
48
  p.catch((e) => {
@@ -103,4 +91,4 @@ const runBuild = async () => {
103
91
  })
104
92
  }
105
93
 
106
- module.exports = runBuild
94
+ export default runBuild
package/tsconfig.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "extends": "@vitus-labs/tools-typescript/lib",
3
+ "compilerOptions": {
4
+ "target": "es5",
5
+ "module": "commonjs",
6
+ "outDir": "lib",
7
+ "rootDir": "src",
8
+ "baseUrl": ".",
9
+ "declarationDir": "./lib/types",
10
+ "paths": {
11
+ "~/*": [
12
+ "src/*"
13
+ ]
14
+ },
15
+ },
16
+ "include": [
17
+ "typings",
18
+ "src",
19
+ ],
20
+ "exclude": [
21
+ "node_modules",
22
+ "__stories__",
23
+ "lib"
24
+ ]
25
+ }