Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added example/packages/bar/bar.js
Empty file.
22 changes: 22 additions & 0 deletions src/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export default class Config {
fileContents: string;
json: JSONValue;
indent: string;
invalid: boolean;

constructor(filePath: string, fileContents: string) {
this.filePath = filePath;
Expand Down Expand Up @@ -125,6 +126,11 @@ export default class Config {
}

getConfig(): { [key: string]: JSONValue } {
if (this.invalid) {
throw new BoltError(
`You need to refresh the Config object for ${this.filePath}`
);
}
let config = this.json;

if (
Expand All @@ -140,6 +146,10 @@ export default class Config {
return config;
}

invalidate() {
this.invalid = true;
}

getDescriptor(): string {
if (this.json && typeof this.json.name === 'string') {
return this.json.name;
Expand Down Expand Up @@ -224,4 +234,16 @@ export default class Config {
.filePath}"`
);
}

getBin() {
let config = this.getConfig();
let bin = config.bin;
if (typeof bin === 'undefined') return;
if (typeof bin === 'string') return bin;
return toObjectOfStrings(
bin,
`package.json#bin must be an object of strings or a string. See "${this
.filePath}"`
);
}
}
13 changes: 11 additions & 2 deletions src/Package.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ export default class Package {
cleaned[depName] = versionRange;
}
}

this.config.write({
await this.config.write({
...this.config.getConfig(),
[depType]: sortObject(cleaned)
});
Expand All @@ -125,6 +124,16 @@ export default class Package {
return null;
}

getDependencyVersionRange(depName: string) {
for (let depType of DEPENDENCY_TYPES) {
const deps = this.config.getDeps(depType);
if (deps && deps[depName]) {
return deps[depName];
}
}
return null;
}

// async maybeUpdateDependencyVersionRange(depName: string, current: string, version: string) {
// let versionRange = '^' + version;
// let updated = false;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"private": true,
"version": "1.0.0",
"name": "fixture-project-nested-workspaces-with-root-dependencies-installed",
"description": "A project with only the root node_modules and symlinks already set up",
"description2": "Packages: foo, bar, baz, zee",
"description3": "bar has a single bin file, baz has two",
"description4": "foo and baz depend on bar, zee depends on baz",
"bolt": {
"workspaces": [
"packages/*"
]
},
"dependencies": {
"external-dep": "^1.0.0",
"external-dep-with-bin": "^1.0.0",
"external-dep-with-two-bins": "^1.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "bar",
"version": "1.0.0",
"dependencies": {
"external-dep": "^1.0.0"
},
"bin": "./bar.js"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "foo",
"version": "1.0.0",
"dependencies": {
"bar": "^1.0.0",
"external-dep": "^1.0.0",
"external-dep-with-bin": "^1.0.0"
},
"bolt": {
"workspaces": ["packages/*"]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "baz",
"version": "1.0.0",
"dependencies": {
"bar": "^1.0.0"
},
"bin": {
"baz-1": "./baz-bin-1.js",
"baz-2": "./baz-bin-2.js"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "zee",
"version": "1.0.0",
"description": "We use the zee package to test all bin symlinking",
"description2": "bar and external-dep-with-bin both have one bin",
"description3": "baz and external-dep... both have two",
"dependencies": {
"bar": "^1.0.0",
"baz": "^1.0.0",
"external-dep-with-bin": "^1.0.0",
"external-dep-with-two-bins": "^1.0.0"
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
},
"dependencies": {
"react": "^15.6.1",
"bar": "^1.0.0"
"@scoped/bar": "^1.0.0"
Copy link
Member Author

@lukebatchelor lukebatchelor Oct 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... I'm going to double check all these fixures. I dont recall changing all these, so I'm thinking my tests may have modified them at some point.

  • find out if I modified all these fixtures or not...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, all good.

}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"version": "1.0.0",
"dependencies": {
"react": "^15.6.1",
"bar": "^1.0.0"
"@scoped/bar": "^1.0.0"
}
}
3 changes: 2 additions & 1 deletion src/__fixtures__/nested-workspaces/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"workspaces": ["packages/*"]
},
"dependencies": {
"react": "^15.6.1"
"react": "^15.6.1",
"left-pad": "^1.1.3"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "baz",
"version": "1.0.0",
"version": "1.0.1",
"dependencies": {
"react": "^15.6.1",
"bar": "^1.0.0"
Expand Down
2 changes: 1 addition & 1 deletion src/__fixtures__/simple-project/packages/bar/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "foo",
"name": "bar",
"version": "1.0.0"
}
2 changes: 1 addition & 1 deletion src/__fixtures__/simple-project/packages/foo/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "bar",
"name": "foo",
"version": "1.0.0"
}
23 changes: 10 additions & 13 deletions src/__tests__/Config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,14 @@ describe('getProjectConfig()', () => {
expect(found).toBe(null);
});

it.only(
'should get the root if in nested package not included in a parent project',
async () => {
let fixturePath = await getFixturePath(
__dirname,
'simple-project-with-excluded-package',
'packages',
'bar'
);
let found = await Config.getProjectConfig(fixturePath);
expect(found).toBe(path.join(fixturePath, 'package.json'));
}
);
it('should get the root if in nested package not included in a parent project', async () => {
let fixturePath = await getFixturePath(
__dirname,
'simple-project-with-excluded-package',
'packages',
'bar'
);
let found = await Config.getProjectConfig(fixturePath);
expect(found).toBe(path.join(fixturePath, 'package.json'));
});
});
Loading