Skip to content

Commit 3c76a14

Browse files
committed
fix: only include the relevant node_modules directory for different build types
1 parent 0d57a14 commit 3c76a14

10 files changed

Lines changed: 347 additions & 204 deletions

File tree

src/apps/catalog/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ export default class CatalogApp
121121

122122
const config = _.merge(
123123
webpackConfig(
124-
dirs,
124+
[dirs.root, dirs.configure, dirs.controllers],
125+
dirs.root,
125126
this.support,
126127
CatalogApp.ENTRY,
127128
CatalogApp.BUNDLE,

src/apps/common.ts

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import * as _ from 'lodash';
22
import * as webpack from 'webpack';
33

4-
import { join, resolve } from "path";
5-
6-
import { Dirs } from '@pie-cli-libs/installer';
4+
import { join, resolve } from 'path';
75

86
import { SupportConfig } from '../framework-support/index';
97
import baseConfig from '../question/build/base-config';
@@ -15,7 +13,6 @@ const logger = buildLogger();
1513
export type Compiler = webpack.compiler.Compiler;
1614

1715
export class Tag {
18-
1916
constructor(readonly name: string, readonly path?: string) {
2017
this.path = this.path || `./${this.name}.js`;
2118
}
@@ -26,30 +23,35 @@ export class Tag {
2623
}
2724

2825
export function removeFiles(dir, files: string[]): Promise<string[]> {
29-
const p: Promise<string>[] = _.map(files, (f) => new Promise((res, reject) => {
30-
remove(join(dir, f), (err) => {
31-
if (err) {
32-
reject(err);
33-
} else {
34-
res(f);
35-
}
36-
});
37-
}));
26+
const p: Promise<string>[] = _.map(
27+
files,
28+
f =>
29+
new Promise((res, reject) => {
30+
remove(join(dir, f), err => {
31+
if (err) {
32+
reject(err);
33+
} else {
34+
res(f);
35+
}
36+
});
37+
})
38+
);
3839
return Promise.all(p);
3940
}
4041

4142
export function webpackConfig(
42-
dirs: Dirs,
43+
resolveModules: string[],
44+
root: string,
4345
support: SupportConfig,
4446
entry: string,
4547
bundle: string,
4648
outpath?: string,
47-
sourceMaps: boolean = false) {
48-
49-
outpath = outpath || dirs.root;
49+
sourceMaps: boolean = false
50+
) {
51+
outpath = outpath || root;
5052
const modules = (d: string) => resolve(join(d, 'node_modules'));
5153

52-
const base = baseConfig(dirs.root);
54+
const base = baseConfig(root);
5355

5456
logger.debug('support modules: ', support.modules);
5557

@@ -58,18 +60,18 @@ export function webpackConfig(
5860
resolve(join(__dirname, '../../node_modules'))
5961
].concat(_.compact(support.modules));
6062

61-
const resolveModules = [
62-
modules(dirs.configure),
63-
modules(dirs.controllers),
64-
modules(dirs.root),
65-
].concat(coreModules);
63+
// const resolveModules = [
64+
// modules(dirs.configure),
65+
// modules(dirs.controllers),
66+
// modules(dirs.root),
67+
// ].concat(coreModules);
6668

67-
const resolveLoaderModules = [
68-
modules(dirs.root),
69-
].concat(coreModules);
69+
resolveModules = resolveModules.concat(coreModules);
70+
71+
const resolveLoaderModules = [modules(root)].concat(coreModules);
7072

7173
const out = _.extend(base, {
72-
context: dirs.root,
74+
context: root,
7375
entry: `./${entry}`,
7476
module: {
7577
rules: base.module.rules.concat(support.rules)
@@ -80,7 +82,7 @@ export function webpackConfig(
8082
},
8183
resolve: {
8284
extensions: _.uniq(['.js'].concat(support.extensions)),
83-
modules: resolveModules,
85+
modules: resolveModules
8486
},
8587
resolveLoader: {
8688
modules: resolveLoaderModules
@@ -94,10 +96,10 @@ export function webpackConfig(
9496
return out;
9597
}
9698

97-
export const clientDependencies = (args: any) => args.configuration.app.dependencies;
99+
export const clientDependencies = (args: any) =>
100+
args.configuration.app.dependencies;
98101

99102
export class Out {
100-
101103
public static build(args) {
102104
return new Out(
103105
args.questionItemTagName ? new Tag(args.questionItemTagName) : undefined,
@@ -113,16 +115,16 @@ export class Out {
113115
readonly viewElements: string = 'pie-view.js',
114116
readonly controllers: string = 'pie-controller.js',
115117
readonly example: string = 'example.html',
116-
readonly archive: string = 'pie-item.tar.gz') { }
117-
118+
readonly archive: string = 'pie-item.tar.gz'
119+
) {}
118120
}
119121

120122
/**
121123
* @deprecated This should be removed
122124
*/
123125
export type Names = {
124-
build: BuildNames,
125-
out: Out
126+
build: BuildNames;
127+
out: Out;
126128
};
127129

128130
type BuildNames = {

src/apps/default/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ export default class DefaultApp
147147
writeFile(join(dirs.root, DefaultApp.CONFIGURE_ENTRY), js);
148148

149149
const config = webpackConfig(
150-
dirs,
150+
[dirs.configure, dirs.root],
151+
dirs.root,
151152
this.support,
152153
DefaultApp.CONFIGURE_ENTRY,
153154
DefaultApp.CONFIGURE_BUNDLE,
@@ -176,7 +177,8 @@ export default class DefaultApp
176177

177178
writeFile(join(dirs.root, 'client.entry.js'), js);
178179
const config = webpackConfig(
179-
dirs,
180+
[dirs.root],
181+
dirs.root,
180182
this.support,
181183
'client.entry.js',
182184
'pie-view.js',
@@ -198,7 +200,8 @@ export default class DefaultApp
198200
const js = generators.controllers(controllers);
199201
writeFile(join(dirs.root, 'controllers.entry.js'), js);
200202
const config = webpackConfig(
201-
dirs,
203+
[dirs.controllers, dirs.root],
204+
dirs.root,
202205
this.support,
203206
'controllers.entry.js',
204207
'pie-controllers.js',
@@ -240,7 +243,8 @@ export default class DefaultApp
240243

241244
writeFile(join(dirs.root, 'all-in-one.entry.js'), js);
242245
const config = webpackConfig(
243-
dirs,
246+
[dirs.root, dirs.configure, dirs.controllers],
247+
dirs.root,
244248
this.support,
245249
'all-in-one.entry.js',
246250
'pie-item.js',

src/apps/info/index.ts

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,26 @@ const logger = buildLogger();
2222
const templatePath = join(__dirname, 'views/index.pug');
2323

2424
export default class InfoApp implements App, Servable {
25-
2625
public static generatedFiles: string[] = [];
2726

28-
public static build(args: any, loadSupport: (JsonConfig) => Promise<SupportConfig>): Promise<App> {
29-
27+
public static build(
28+
args: any,
29+
loadSupport: (JsonConfig) => Promise<SupportConfig>
30+
): Promise<App> {
3031
const dir = resolve(args.dir || process.cwd());
3132

3233
if (!existsSync(join(dir, 'docs/demo'))) {
33-
throw new Error(`Can't find a 'docs/demo' directory in path: ${dir}. Is this a pie directory?`);
34+
throw new Error(
35+
`Can't find a 'docs/demo' directory in path: ${dir}. Is this a pie directory?`
36+
);
3437
}
3538

3639
const config = JsonConfig.build(join(dir, 'docs/demo'), args);
3740
const session = Session.build(join(dir, 'docs/demo'), args);
3841

39-
return loadSupport(config)
40-
.then(support => new InfoApp(dir, config, support, session));
42+
return loadSupport(config).then(
43+
support => new InfoApp(dir, config, support, session)
44+
);
4145
}
4246

4347
private static BUNDLE = 'info.bundle.js';
@@ -46,11 +50,12 @@ export default class InfoApp implements App, Servable {
4650
private template: any;
4751
private installer: Install;
4852

49-
constructor(private pieRoot: string,
53+
constructor(
54+
private pieRoot: string,
5055
readonly config: JsonConfig,
5156
private support: SupportConfig,
52-
readonly session: Session) {
53-
57+
readonly session: Session
58+
) {
5459
this.template = pug.compileFile(templatePath);
5560

5661
this.installer = new Install(config.dir, config.raw);
@@ -62,7 +67,7 @@ export default class InfoApp implements App, Servable {
6267
public watchableFiles(): string[] {
6368
return [
6469
resolve(join(this.pieRoot, 'README.md')),
65-
resolve(join(this.pieRoot, 'package.json')),
70+
resolve(join(this.pieRoot, 'package.json'))
6671
];
6772
}
6873

@@ -74,35 +79,42 @@ export default class InfoApp implements App, Servable {
7479

7580
await writeEntryJs(join(dirs.root, InfoApp.ENTRY), js);
7681

77-
const config = webpackConfig(dirs, this.support, InfoApp.ENTRY, InfoApp.BUNDLE, null, opts.sourceMaps);
82+
const resolveModules = [dirs.root, dirs.configure, dirs.controllers];
83+
const config = webpackConfig(
84+
resolveModules,
85+
dirs.root,
86+
this.support,
87+
InfoApp.ENTRY,
88+
InfoApp.BUNDLE,
89+
null,
90+
opts.sourceMaps
91+
);
7892

7993
const cssRule = config.module.rules.find(u => {
8094
const match = u.test.source === '\\.css$';
8195
return match;
8296
});
8397

84-
cssRule.exclude = [
85-
/.*highlight\.js.*/,
86-
];
98+
cssRule.exclude = [/.*highlight\.js.*/];
8799

88100
// load in raw css for markdown element
89-
config.module.rules = [{
90-
test: /.*highlight\.js.*default\.css$/,
91-
use: [
92-
'raw-loader',
93-
],
94-
},
95-
{
96-
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2|otf)$/,
97-
use: [
98-
{
99-
loader: 'url-loader',
100-
options: {
101-
limit: 10000
101+
config.module.rules = [
102+
{
103+
test: /.*highlight\.js.*default\.css$/,
104+
use: ['raw-loader']
105+
},
106+
{
107+
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2|otf)$/,
108+
use: [
109+
{
110+
loader: 'url-loader',
111+
options: {
112+
limit: 10000
113+
}
102114
}
103-
}
104-
]
105-
}].concat(config.module.rules);
115+
]
116+
}
117+
].concat(config.module.rules);
106118

107119
writeConfig(join(dirs.root, 'info.webpack.config.js'), config);
108120

@@ -115,7 +127,7 @@ export default class InfoApp implements App, Servable {
115127

116128
linkCompilerToServer('main', compiler, server);
117129

118-
const reload = (name) => {
130+
const reload = name => {
119131
logger.info('File Changed: ', name);
120132
this.config.reload();
121133
this.session.reload();
@@ -126,12 +138,11 @@ export default class InfoApp implements App, Servable {
126138
dirs,
127139
pkgs,
128140
reload,
129-
server: server.httpServer,
141+
server: server.httpServer
130142
};
131143
}
132144

133145
private router(compiler: webpack.Compiler): express.Router {
134-
135146
const router = express.Router();
136147

137148
const middleware = webpackMiddleware(compiler, {
@@ -147,12 +158,10 @@ export default class InfoApp implements App, Servable {
147158
router.use(middleware);
148159

149160
router.get('/', (req, res) => {
150-
151161
const pkg = readJsonSync(join(this.pieRoot, 'package.json'));
152162
const readme = readFileSync(join(this.pieRoot, 'README.md'), 'utf8');
153163

154164
const page = this.template({
155-
156165
demo: {
157166
config: {
158167
langs: this.config.langs,
@@ -174,7 +183,7 @@ export default class InfoApp implements App, Servable {
174183
`/${InfoApp.BUNDLE}`
175184
]),
176185
orgRepo: {
177-
repo: pkg.name,
186+
repo: pkg.name
178187
}
179188
});
180189

0 commit comments

Comments
 (0)