Skip to content

Commit b19aadc

Browse files
committed
Make sure a missing main field in package.json is not a problem
1 parent 72f9d0e commit b19aadc

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## Fixed
11+
12+
- No longer required to provide a "main" field in your `package.json`. This is still messy but at least works well enough for a single entrypoint.
13+
1014
### Changed
1115

12-
- Loosened up `typescript` dependency to `^3`
16+
- Loosened up `typescript` dependency to `^3`.
17+
- Internally now tracks whether multiple entrypoints are passed to simplify some code.
1318

1419
## [0.1.0] - 2019-07-27
1520

src/index.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ interface createRollupConfigOptions {
2828
externalDependencies?: string[];
2929
input: string;
3030
nodeTarget?: string;
31+
withMultipleInputs: boolean;
3132
outputDir: string;
3233
pkgMain: string;
3334
}
@@ -37,6 +38,7 @@ async function createRollupConfig({
3738
externalDependencies = [],
3839
input,
3940
nodeTarget = 'current',
41+
withMultipleInputs,
4042
outputDir,
4143
pkgMain,
4244
}: createRollupConfigOptions) {
@@ -50,7 +52,7 @@ async function createRollupConfig({
5052
input,
5153
external: id => {
5254
// a special case for when we are importing a local index
53-
if (id === '.') {
55+
if (withMultipleInputs && id === '.') {
5456
return true;
5557
}
5658

@@ -102,9 +104,11 @@ async function createRollupConfig({
102104
const inputFileName = parse(input).name;
103105
const bannerFn = () => banner;
104106

105-
const paths = {
106-
'.': `./${basename(pkgMain)}`,
107-
};
107+
const paths = {};
108+
109+
if (pkgMain) {
110+
paths['.'] = `./${basename(pkgMain)}`;
111+
}
108112

109113
const outputOptions: OutputOptions[] = [
110114
{
@@ -141,6 +145,8 @@ export async function bundler({
141145

142146
const inputs = await glob(input, { absolute: true });
143147

148+
const withMultipleInputs = inputs.length > 1;
149+
144150
for (let idx = 0; idx < inputs.length; idx++) {
145151
const input = inputs[idx];
146152

@@ -153,6 +159,7 @@ export async function bundler({
153159
externalDependencies,
154160
input,
155161
nodeTarget,
162+
withMultipleInputs,
156163
outputDir,
157164
pkgMain: pkg.main,
158165
});

0 commit comments

Comments
 (0)