Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit ee42a5a

Browse files
committed
fix: use custom rollup config to build instead of libundler
1 parent 0284f52 commit ee42a5a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+490
-945
lines changed

core/docz-core/librc.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

core/docz-core/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@
44
"description": "All docz core logic of bundle and parsing is included on this package",
55
"license": "MIT",
66
"main": "dist/index.js",
7-
"module": "dist/index.m.js",
7+
"module": "dist/index.esm.js",
88
"typings": "dist/index.d.ts",
9-
"source": "src/index.ts",
109
"files": [
1110
"dist/",
1211
"package.json",
1312
"README.md"
1413
],
1514
"scripts": {
16-
"dev": "libundler watch --ts -e all",
17-
"build": "libundler build --ts -e all --c",
15+
"dev": "cross-env NODE_ENV=development yarn build -w",
16+
"build": "cross-env NODE_ENV=production rollup -c",
1817
"fix": "run-s fix:*",
1918
"fix:prettier": "prettier \"src/**/*.{ts,tsx,md,mdx,js,jsx,json}\" --write",
2019
"fix:tslint": "tslint --fix --project .",
@@ -54,6 +53,7 @@
5453
"lodash": "^4.17.11",
5554
"mini-html-webpack-plugin": "^0.2.3",
5655
"p-reduce": "^1.0.0",
56+
"pretty-error": "^2.1.1",
5757
"react-dev-utils": "^7.0.0",
5858
"react-docgen": "^2.21.0",
5959
"react-docgen-actual-name-handler": "0.13.5",
@@ -73,7 +73,7 @@
7373
"thread-loader": "^2.1.1",
7474
"titleize": "^1.0.1",
7575
"url-loader": "^1.1.2",
76-
"webpack": "^4.28.2",
76+
"webpack": "^4.28.3",
7777
"webpack-bundle-analyzer": "^3.0.3",
7878
"webpack-chain": "^5.0.1",
7979
"webpack-dev-server": "^3.1.14",

core/docz-core/rollup.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { config, copy } from 'docz-rollup'
2+
3+
export default config({
4+
input: 'src/index.ts',
5+
plugins: [copy('templates', 'dist/templates')],
6+
})

core/docz-core/src/bundler/build.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import * as fs from 'fs-extra'
2-
import chalk from 'chalk'
3-
import logger, { Signale } from 'signale'
2+
import * as logger from 'signale'
3+
import * as envDotProp from 'env-dot-prop'
44
import webpack, { Configuration as CFG } from 'webpack'
5-
import FSR from 'react-dev-utils/FileSizeReporter'
6-
import formatWebpackMessages from 'react-dev-utils/formatWebpackMessages'
7-
import envDotProp from 'env-dot-prop'
5+
import chalk from 'chalk'
6+
7+
const FSR = require('react-dev-utils/FileSizeReporter')
8+
const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages')
89

910
import * as paths from '../config/paths'
1011

@@ -109,7 +110,7 @@ const onError = (err: Error) => {
109110
}
110111

111112
export const build = async (config: CFG, dist: string, publicDir: string) => {
112-
const interactive = new Signale({ interactive: true, scope: 'build' })
113+
const interactive = new logger.Signale({ interactive: true, scope: 'build' })
113114

114115
try {
115116
interactive.start('Creating an optimized bundle')

core/docz-core/src/bundler/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as path from 'path'
22
import { Configuration } from 'webpack'
3+
import * as envDotProp from 'env-dot-prop'
34
import Config from 'webpack-chain'
4-
import envDotProp from 'env-dot-prop'
55

66
import * as loaders from './loaders'
77
import * as plugins from './plugins'

core/docz-core/src/bundler/server.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@ import chalk from 'chalk'
22
import logger from 'signale'
33
import WebpackDevServer from 'webpack-dev-server'
44
import { Configuration as Config } from 'webpack'
5+
import PrettyError from 'pretty-error'
56

67
import { devServerConfig } from './devserver'
78
import { Config as Args } from '../config/argv'
89
import { ServerHooks as Hooks } from '../lib/Bundler'
910

11+
const pe = new PrettyError()
1012
const createCompiler = (config: Config) =>
1113
new Promise<any>(resolve => {
1214
try {
1315
resolve(require('webpack')(config))
1416
} catch (err) {
1517
logger.fatal(chalk.red('Failed to compile.'))
16-
logger.fatal()
17-
logger.fatal(err.message || err)
18-
logger.fatal()
18+
pe.render(err)
1919
process.exit(1)
2020
}
2121
})

core/docz-core/src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import yargs from 'yargs'
1+
import * as yargs from 'yargs'
22

33
import { setArgs } from './config/argv'
44
import { setEnv } from './config/env'

core/docz-core/src/commands/build.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Arguments } from 'yargs'
2-
import logger from 'signale'
3-
import envDotProp from 'env-dot-prop'
2+
import * as envDotProp from 'env-dot-prop'
3+
import PrettyError from 'pretty-error'
44

55
import { Plugin } from '../lib/Plugin'
66
import { Entries } from '../lib/Entries'
@@ -9,6 +9,7 @@ import { parseConfig } from '../config/docz'
99
import { bundler as webpack } from '../bundler'
1010
import * as states from '../states'
1111

12+
const pe = new PrettyError()
1213
export const build = async (args: Arguments<any>) => {
1314
const env = envDotProp.get('node.env')
1415
const config = await parseConfig(args)
@@ -32,7 +33,7 @@ export const build = async (args: Arguments<any>) => {
3233
await run('onPostBuild', config)
3334
await dataServer.close()
3435
} catch (err) {
35-
logger.fatal(err)
36+
pe.render(err)
3637
process.exit(1)
3738
}
3839
}

core/docz-core/src/commands/dev.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
process.setMaxListeners(Infinity)
22

33
import { Arguments } from 'yargs'
4-
import logger from 'signale'
5-
import envDotProp from 'env-dot-prop'
4+
import * as logger from 'signale'
5+
import * as envDotProp from 'env-dot-prop'
6+
import PrettyError from 'pretty-error'
67

78
import { Entries } from '../lib/Entries'
89
import { DataServer } from '../lib/DataServer'
@@ -11,6 +12,7 @@ import { onSignal } from '../utils/on-signal'
1112
import { bundler as webpack } from '../bundler'
1213
import * as states from '../states'
1314

15+
const pe = new PrettyError()
1416
export const dev = async (args: Arguments<any>) => {
1517
const env = envDotProp.get('node.env')
1618
const config = await parseConfig(args)
@@ -23,7 +25,8 @@ export const dev = async (args: Arguments<any>) => {
2325
try {
2426
await Entries.writeApp(config, true)
2527
} catch (err) {
26-
logger.fatal('Failed to build your files:', err)
28+
logger.fatal('Failed to build your files')
29+
pe.render(err)
2730
process.exit(1)
2831
}
2932

@@ -41,7 +44,8 @@ export const dev = async (args: Arguments<any>) => {
4144
await dataServer.init()
4245
await dataServer.listen()
4346
} catch (err) {
44-
logger.fatal('Failed to process data server:', err)
47+
logger.fatal('Failed to process data server')
48+
pe.render(err)
4549
await dataServer.close()
4650
process.exit(1)
4751
}

core/docz-core/src/config/argv.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as fs from 'fs-extra'
22
import { Argv as Yargs } from 'yargs'
3-
import envDotProp from 'env-dot-prop'
3+
import * as envDotProp from 'env-dot-prop'
44
import humanize from 'humanize-string'
55
import titleize from 'titleize'
6-
import get from 'lodash/get'
6+
import { get } from 'lodash/fp'
77

88
import { Plugin } from '../lib/Plugin'
99
import { BabelRC } from '../config/babel'
@@ -12,14 +12,13 @@ import * as paths from '../config/paths'
1212
const getEnv = (val: string | string[], defaultValue: any = null): any =>
1313
envDotProp.get(val, defaultValue, { parse: true })
1414

15-
const removeScope = (name: string) => name.replace(/^@.*\//, '')
1615
const getInitialTitle = (pkg: any): string => {
17-
const name = get(pkg, 'name') || 'MyDoc'
18-
return titleize(humanize(removeScope(name)))
16+
const name = get('name', pkg) || 'MyDoc'
17+
return titleize(humanize(name.replace(/^@.*\//, '')))
1918
}
2019

2120
const getInitialDescription = (pkg: any): string =>
22-
get(pkg, 'description') || 'My awesome app using docz'
21+
get('description', pkg) || 'My awesome app using docz'
2322

2423
export type Env = 'production' | 'development'
2524
export type ThemeConfig = Record<string, any>

core/docz-core/src/config/env.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as path from 'path'
2-
import envDotProp from 'env-dot-prop'
2+
import * as envDotProp from 'env-dot-prop'
33

44
import { root, resolveApp } from './paths'
55

core/docz-core/src/config/paths.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as fs from 'fs'
22
import * as path from 'path'
3-
import resolve from 'resolve'
3+
import * as resolve from 'resolve'
44

55
const ensureSlash = (filepath: any, needsSlash: boolean) => {
66
const hasSlash = filepath.endsWith('/')

core/docz-core/src/lib/Entries.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import * as path from 'path'
22
import * as fs from 'fs-extra'
3-
import { mdast } from 'docz-utils'
3+
import { parseMdx } from 'docz-utils/lib/mdast'
44
import { touch, compiled } from 'docz-utils/lib/fs'
55
import glob from 'fast-glob'
6+
import PrettyError from 'pretty-error'
67

78
import * as paths from '../config/paths'
89

@@ -13,6 +14,7 @@ import { getRepoEditUrl } from '../utils/repo-info'
1314

1415
export const fromTemplates = (file: string) => path.join(paths.templates, file)
1516

17+
const pe = new PrettyError()
1618
const mapToObj = (map: Map<any, any>) =>
1719
Array.from(map.entries()).reduce(
1820
(obj, [key, value]) => ({ ...obj, [`${key}`]: value }),
@@ -88,7 +90,7 @@ export class Entries {
8890

8991
const createEntry = async (file: string) => {
9092
try {
91-
const ast = await mdast.parseMdx(file)
93+
const ast = await parseMdx(file)
9294
const entry = new Entry(ast, file, src)
9395

9496
if (this.repoEditUrl) entry.setLink(this.repoEditUrl)
@@ -99,6 +101,8 @@ export class Entries {
99101
...rest,
100102
}
101103
} catch (err) {
104+
console.log(err)
105+
config.debug && pe.render(err)
102106
return null
103107
}
104108
}

core/docz-core/src/lib/Entry.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import * as path from 'path'
22
import * as crypto from 'crypto'
33
import slugify from '@sindresorhus/slugify'
44
import humanize from 'humanize-string'
5-
import { mdast } from 'docz-utils'
5+
import {
6+
getParsedData,
7+
headingsFromAst,
8+
Heading,
9+
ParsedData,
10+
} from 'docz-utils/lib/mdast'
611

712
import * as paths from '../config/paths'
813

@@ -21,7 +26,7 @@ export interface EntryObj {
2126
route: string
2227
order: number
2328
menu: string | null
24-
headings: mdast.Heading[]
29+
headings: Heading[]
2530
[key: string]: any
2631
}
2732

@@ -36,14 +41,14 @@ export class Entry {
3641
public name: string
3742
public order: number
3843
public menu: string | null
39-
public headings: mdast.Heading[]
44+
public headings: Heading[]
4045
public settings: {
4146
[key: string]: any
4247
}
4348

4449
constructor(ast: any, file: string, src: string) {
4550
const filepath = this.getFilepath(file, src)
46-
const parsed = mdast.getParsedData(ast)
51+
const parsed = getParsedData(ast)
4752
const name = this.getName(filepath, parsed)
4853

4954
this.id = createId(file)
@@ -54,7 +59,7 @@ export class Entry {
5459
this.name = name
5560
this.order = parsed.order || 0
5661
this.menu = parsed.menu || null
57-
this.headings = mdast.headingsFromAst(ast)
62+
this.headings = headingsFromAst(ast)
5863
this.settings = parsed
5964
}
6065

@@ -75,7 +80,7 @@ export class Entry {
7580
return filepath
7681
}
7782

78-
private getName(filepath: string, parsed: mdast.ParsedData): string {
83+
private getName(filepath: string, parsed: ParsedData): string {
7984
const filename = humanize(path.parse(filepath).name)
8085
return parsed && parsed.name ? parsed.name : filename
8186
}

core/docz-core/src/utils/docgen.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import importedProptypesHandler from 'react-docgen-imported-proptype-handler'
88
import actualNameHandler from 'react-docgen-actual-name-handler'
99
import reactDocgenTs from 'react-docgen-typescript'
1010
import reactDocgen from 'react-docgen'
11+
import PrettyError from 'pretty-error'
1112

1213
import * as paths from '../config/paths'
1314
import { Config } from '../config/argv'
1415

16+
const pe = new PrettyError()
1517
const fileFullPath = (filepath: string) => path.join(paths.root, filepath)
1618

1719
const tsParser = async (files: string[], config: Config) => {
@@ -32,7 +34,8 @@ const tsParser = async (files: string[], config: Config) => {
3234
.map(filepath => ({ [fileFullPath(filepath)]: parse(filepath) }))
3335
.reduce((obj, val) => ({ ...obj, ...val }), {})
3436
} catch (err) {
35-
logger.fatal('Error parsing static types.', err)
37+
logger.fatal('Error parsing static types.')
38+
pe.render(err)
3639
return {}
3740
}
3841
}
@@ -55,9 +58,7 @@ const jsParser = (files: string[], config: Config) => {
5558
const data = reactDocgen.parse(code, resolver, handlers)
5659
memo[fileFullPath(filepath)] = data
5760
} catch (err) {
58-
if (err.message !== 'No suitable component definition found.') {
59-
logger.fatal('Error:', filepath, err)
60-
}
61+
pe.render(err)
6162
}
6263

6364
return memo

core/docz-core/tsconfig.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
{
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
4-
"declaration": true,
4+
"module": "esnext",
55
"outDir": "dist",
66
"rootDir": "src",
7-
"typeRoots": ["../../node_modules/@types", "node_modules/@types", "src/types"]
7+
"declaration": true,
8+
"types": ["node"],
9+
"typeRoots": ["../../node_modules/@types", "node_modules/@types"]
810
},
9-
"include": ["src/**/*"],
11+
"include": ["src/**/*", "src/types.d.ts"],
1012
"exclude": ["node_modules/**"]
1113
}

0 commit comments

Comments
 (0)