New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add "version" string and parsed "versionInfo" #1878
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ const { | |
rmdirRecursive, | ||
mkdirRecursive, | ||
readdirRecursive, | ||
parseSemver, | ||
} = require('./utils'); | ||
|
||
if (require.main === module) { | ||
|
@@ -26,14 +27,21 @@ if (require.main === module) { | |
|
||
copyFile('./LICENSE', './dist/LICENSE'); | ||
copyFile('./README.md', './dist/README.md'); | ||
writeFile('./dist/package.json', buildPackageJSON()); | ||
|
||
const srcFiles = readdirRecursive('./src', { ignoreDir: /^__.*__$/ }); | ||
for (const filepath of srcFiles) { | ||
if (filepath.endsWith('.js')) { | ||
buildJSFile(filepath); | ||
} | ||
} | ||
|
||
const packageJSON = buildPackageJSON(); | ||
assert( | ||
packageJSON.version === require('../dist/version').version, | ||
'Version in package.json and version.js should match', | ||
); | ||
|
||
writeFile('./dist/package.json', packageJSON); | ||
} | ||
|
||
function buildJSFile(filepath) { | ||
|
@@ -52,13 +60,14 @@ function buildPackageJSON() { | |
delete packageJSON.scripts; | ||
delete packageJSON.devDependencies; | ||
|
||
const { version } = packageJSON; | ||
const match = /^[0-9]+\.[0-9]+\.[0-9]+-?([^.]*)/.exec(version); | ||
assert(match, 'Version does not match semver spec.'); | ||
const tag = match[1]; | ||
assert(!tag || tag === 'rc', 'Only "rc" tag is supported.'); | ||
const { preReleaseTag } = parseSemver(packageJSON.version); | ||
if (preReleaseTag != null) { | ||
const [tag] = preReleaseTag.split('.'); | ||
assert(tag === 'rc', 'Only "rc" tag is supported.'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see the code had this check before, but I'm just curious why only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @martijnwalraven Thanks for the review 👍 |
||
|
||
assert(!packageJSON.publishConfig, 'Can not override "publishConfig".'); | ||
packageJSON.publishConfig = { tag: tag || 'latest' }; | ||
} | ||
|
||
assert(!packageJSON.publishConfig, 'Can not override "publishConfig".'); | ||
packageJSON.publishConfig = { tag: tag || 'latest' }; | ||
return JSON.stringify(packageJSON, null, 2); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @noflow | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const { version } = require('../package.json'); | ||
const { writeFile, parseSemver } = require('./utils'); | ||
|
||
const versionInfo = parseSemver(version); | ||
const body = `/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow strict | ||
*/ | ||
|
||
/** | ||
* Note: This file is autogenerated using "resources/gen-version.js" script and | ||
* automatically updated by "yarn version" command. | ||
*/ | ||
|
||
/** | ||
* A string containing the version of the GraphQL.js library | ||
*/ | ||
export const version = '${version}'; | ||
|
||
/** | ||
* An object containing the components of the GraphQL.js version string | ||
*/ | ||
export const versionInfo = Object.freeze({ | ||
major: ${versionInfo.major}, | ||
minor: ${versionInfo.minor}, | ||
patch: ${versionInfo.patch}, | ||
preReleaseTag: ${JSON.stringify(versionInfo.preReleaseTag || null)}, | ||
}); | ||
`; | ||
|
||
if (require.main === module) { | ||
writeFile('./src/version.js', body); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow strict | ||
*/ | ||
|
||
import { expect } from 'chai'; | ||
import { describe, it } from 'mocha'; | ||
import { version, versionInfo } from '../version'; | ||
|
||
describe('Version', () => { | ||
it('version', () => { | ||
expect(version).to.be.a('string'); | ||
expect(version).to.match(/^\d+\.\d+\.\d(-rc.\d+)?$/); | ||
}); | ||
|
||
it('versionInfo', () => { | ||
expect(versionInfo).to.be.an('object'); | ||
expect(versionInfo).to.have.all.keys( | ||
'major', | ||
'minor', | ||
'patch', | ||
'preReleaseTag', | ||
); | ||
|
||
const { major, minor, patch, preReleaseTag } = versionInfo; | ||
|
||
expect(major).to.be.a('number'); | ||
expect(minor).to.be.a('number'); | ||
expect(patch).to.be.a('number'); | ||
if (preReleaseTag !== null) { | ||
expect(preReleaseTag).to.be.a('string'); | ||
} | ||
|
||
expect( | ||
`${major}.${minor}.${patch}` + | ||
(preReleaseTag !== null ? '-' + preReleaseTag : ''), | ||
).to.equal(version); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow strict | ||
*/ | ||
|
||
/** | ||
* Note: This file is autogenerated using "resources/gen-version.js" script and | ||
* automatically updated by "yarn version" command. | ||
*/ | ||
|
||
/** | ||
* A string containing the version of the GraphQL.js library | ||
*/ | ||
export const version = '14.3.0'; | ||
|
||
/** | ||
* An object containing the components of the GraphQL.js version string | ||
*/ | ||
export const versionInfo = Object.freeze({ | ||
major: 14, | ||
minor: 3, | ||
patch: 0, | ||
preReleaseTag: null, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check guarantees that
package.json
andversion.js
are always in sync.