Fix process.env.version
in browser-bundles (#206)
* Fix `process.env.version` in browser-bundles - also fix tsdoc warns in mjs files Co-authored-by: Fülöp Kovács <kovacs.fulop@gmail.com> Co-authored-by: Cole Lawrence <cole@colelawrence.com> * Change to `process.env.THEATRE_VERSION` Co-authored-by: Fülöp Kovács <kovacs.fulop@gmail.com> Co-authored-by: Cole Lawrence <cole@colelawrence.com>
This commit is contained in:
parent
d7fc381137
commit
bebf281517
13 changed files with 39 additions and 24 deletions
|
@ -73,6 +73,7 @@ module.exports = {
|
||||||
rules: {
|
rules: {
|
||||||
'react/jsx-uses-react': 'error',
|
'react/jsx-uses-react': 'error',
|
||||||
'react/jsx-uses-vars': 'error',
|
'react/jsx-uses-vars': 'error',
|
||||||
|
'tsdoc/syntax': 'off',
|
||||||
},
|
},
|
||||||
parser: 'espree',
|
parser: 'espree',
|
||||||
parserOptions: {
|
parserOptions: {
|
||||||
|
|
|
@ -109,7 +109,7 @@ const packagesToPublish = [
|
||||||
* @param {string} hash - Hash of the latest commit (or any other string)
|
* @param {string} hash - Hash of the latest commit (or any other string)
|
||||||
* @returns {Promise<() => void>} - An async function that restores the package.json files to their original version
|
* @returns {Promise<() => void>} - An async function that restores the package.json files to their original version
|
||||||
*/
|
*/
|
||||||
async function assignVersions(workspacesListObjects, hash) {
|
async function writeVersionsToPackageJSONs(workspacesListObjects, hash) {
|
||||||
/**
|
/**
|
||||||
* An array of functions each of which restores a certain package.json to its original state
|
* An array of functions each of which restores a certain package.json to its original state
|
||||||
* @type {Array<() => void>}
|
* @type {Array<() => void>}
|
||||||
|
@ -181,7 +181,10 @@ async function releaseToVerdaccio() {
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.map((x) => JSON.parse(x))
|
.map((x) => JSON.parse(x))
|
||||||
|
|
||||||
const restorePackages = await assignVersions(workspacesListObjects, version)
|
const restorePackages = await writeVersionsToPackageJSONs(
|
||||||
|
workspacesListObjects,
|
||||||
|
version,
|
||||||
|
)
|
||||||
|
|
||||||
process.on('SIGINT', async function cleanup(a) {
|
process.on('SIGINT', async function cleanup(a) {
|
||||||
restorePackages()
|
restorePackages()
|
||||||
|
|
|
@ -4,6 +4,9 @@ import type {Plugin} from 'esbuild'
|
||||||
|
|
||||||
const definedGlobals = {
|
const definedGlobals = {
|
||||||
global: 'window',
|
global: 'window',
|
||||||
|
'process.env.THEATRE_VERSION': JSON.stringify(
|
||||||
|
require('../package.json').version,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
function createBundles(watch: boolean) {
|
function createBundles(watch: boolean) {
|
||||||
|
|
|
@ -2,7 +2,9 @@ import path = require('path')
|
||||||
import {build} from 'esbuild'
|
import {build} from 'esbuild'
|
||||||
|
|
||||||
const definedGlobals = {
|
const definedGlobals = {
|
||||||
'process.env.version': JSON.stringify(require('../package.json').version),
|
'process.env.THEATRE_VERSION': JSON.stringify(
|
||||||
|
require('../package.json').version,
|
||||||
|
),
|
||||||
'process.env.NODE_ENV': JSON.stringify('production'),
|
'process.env.NODE_ENV': JSON.stringify('production'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,13 +61,17 @@ function getNewVersionName(packageName, commitHash) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assigns the new versions to the packages
|
* Assigns the latest version names ({@link getNewVersionName}) to the packages' `package.json`s
|
||||||
*
|
*
|
||||||
* @param {{name: string, location: string}[]} workspacesListObjects - An Array of objects containing information about the workspaces
|
* @param {{name: string, location: string}[]} workspacesListObjects - An Array of objects containing information about the workspaces
|
||||||
* @param {string} latestCommitHash - Hash of the latest commit
|
* @param {string} latestCommitHash - Hash of the latest commit
|
||||||
* @returns {Promise<Record<string, string>>} - A record of {[packageId]: assignedVersion}
|
* @returns {Promise<Record<string, string>>} - A record of {[packageId]: assignedVersion}
|
||||||
*/
|
*/
|
||||||
async function assignVersions(workspacesListObjects, latestCommitHash) {
|
async function writeVersionsToPackageJSONs(
|
||||||
|
workspacesListObjects,
|
||||||
|
latestCommitHash,
|
||||||
|
) {
|
||||||
|
/** @type {Record<string, string>} */
|
||||||
const assignedVersionByPackageName = {}
|
const assignedVersionByPackageName = {}
|
||||||
for (const workspaceData of workspacesListObjects) {
|
for (const workspaceData of workspacesListObjects) {
|
||||||
const pathToPackage = path.resolve(
|
const pathToPackage = path.resolve(
|
||||||
|
@ -130,6 +134,11 @@ async function assignVersions(workspacesListObjects, latestCommitHash) {
|
||||||
const fakeMergeCommitHashLength = (await $`git log -1 --pretty=format:%h`)
|
const fakeMergeCommitHashLength = (await $`git log -1 --pretty=format:%h`)
|
||||||
.stdout.length
|
.stdout.length
|
||||||
|
|
||||||
|
if (!process.env.GITHUB_SHA)
|
||||||
|
throw new Error(
|
||||||
|
'expected `process.env.GITHUB_SHA` to be defined but it was not',
|
||||||
|
)
|
||||||
|
|
||||||
const latestCommitHash = process.env.GITHUB_SHA.slice(
|
const latestCommitHash = process.env.GITHUB_SHA.slice(
|
||||||
0,
|
0,
|
||||||
fakeMergeCommitHashLength,
|
fakeMergeCommitHashLength,
|
||||||
|
@ -142,7 +151,7 @@ async function assignVersions(workspacesListObjects, latestCommitHash) {
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.map((x) => JSON.parse(x))
|
.map((x) => JSON.parse(x))
|
||||||
|
|
||||||
const assignedVersionByPackageName = await assignVersions(
|
const assignedVersionByPackageName = await writeVersionsToPackageJSONs(
|
||||||
workspacesListObjects,
|
workspacesListObjects,
|
||||||
latestCommitHash,
|
latestCommitHash,
|
||||||
)
|
)
|
||||||
|
|
|
@ -134,7 +134,7 @@ const packagesWhoseVersionsShouldBump = [
|
||||||
const skipTypescriptEmit = argv['skip-ts'] === true
|
const skipTypescriptEmit = argv['skip-ts'] === true
|
||||||
|
|
||||||
console.log('Assigning versions')
|
console.log('Assigning versions')
|
||||||
await assignVersions(version)
|
await writeVersionsToPackageJSONs(version)
|
||||||
|
|
||||||
console.log('Building all packages')
|
console.log('Building all packages')
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
|
@ -163,7 +163,7 @@ const packagesWhoseVersionsShouldBump = [
|
||||||
|
|
||||||
$.verbose = true
|
$.verbose = true
|
||||||
|
|
||||||
await assignVersions(version)
|
await writeVersionsToPackageJSONs(version)
|
||||||
|
|
||||||
console.log('Committing/tagging')
|
console.log('Committing/tagging')
|
||||||
|
|
||||||
|
@ -188,7 +188,7 @@ const packagesWhoseVersionsShouldBump = [
|
||||||
})()
|
})()
|
||||||
|
|
||||||
/** @param {string} monorepoVersion */
|
/** @param {string} monorepoVersion */
|
||||||
async function assignVersions(monorepoVersion) {
|
async function writeVersionsToPackageJSONs(monorepoVersion) {
|
||||||
for (const packagePathRelativeFromRoot of packagesWhoseVersionsShouldBump) {
|
for (const packagePathRelativeFromRoot of packagesWhoseVersionsShouldBump) {
|
||||||
const pathToPackage = path.resolve(
|
const pathToPackage = path.resolve(
|
||||||
__dirname,
|
__dirname,
|
||||||
|
|
|
@ -5,12 +5,7 @@
|
||||||
"checkJs": true,
|
"checkJs": true,
|
||||||
"noEmit": true,
|
"noEmit": true,
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"types": [
|
"types": ["zx", "node"]
|
||||||
"zx"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"include": [
|
"include": ["*.mjs", "**/*.mjs"]
|
||||||
"*.mjs",
|
|
||||||
"**/*.mjs",
|
|
||||||
]
|
|
||||||
}
|
}
|
|
@ -18,7 +18,7 @@ export default class CoreBundle {
|
||||||
}
|
}
|
||||||
|
|
||||||
get version() {
|
get version() {
|
||||||
return process.env.version
|
return process.env.THEATRE_VERSION
|
||||||
}
|
}
|
||||||
|
|
||||||
getBitsForStudio(studio: Studio, callback: (bits: CoreBits) => void) {
|
getBitsForStudio(studio: Studio, callback: (bits: CoreBits) => void) {
|
||||||
|
|
|
@ -30,8 +30,10 @@ function registerCoreBundle() {
|
||||||
if (typeof window == 'undefined') return
|
if (typeof window == 'undefined') return
|
||||||
|
|
||||||
// another core bundle may already be registered
|
// another core bundle may already be registered
|
||||||
|
|
||||||
|
const existingBundle: CoreBundle | undefined =
|
||||||
// @ts-ignore ignore
|
// @ts-ignore ignore
|
||||||
const existingBundle = window[globalVariableNames.coreBundle]
|
window[globalVariableNames.coreBundle]
|
||||||
|
|
||||||
if (typeof existingBundle !== 'undefined') {
|
if (typeof existingBundle !== 'undefined') {
|
||||||
if (
|
if (
|
||||||
|
|
|
@ -2,7 +2,7 @@ import path from 'path'
|
||||||
import {build} from 'esbuild'
|
import {build} from 'esbuild'
|
||||||
|
|
||||||
export const definedGlobals = {
|
export const definedGlobals = {
|
||||||
'process.env.version': JSON.stringify(
|
'process.env.THEATRE_VERSION': JSON.stringify(
|
||||||
require('../studio/package.json').version,
|
require('../studio/package.json').version,
|
||||||
),
|
),
|
||||||
// json-touch-patch (an unmaintained package) reads this value. We patch it to just 'Set', becauce
|
// json-touch-patch (an unmaintained package) reads this value. We patch it to just 'Set', becauce
|
||||||
|
|
2
theatre/globals.d.ts
vendored
2
theatre/globals.d.ts
vendored
|
@ -11,7 +11,7 @@ interface NodeModule {
|
||||||
|
|
||||||
interface ProcessEnv {
|
interface ProcessEnv {
|
||||||
NODE_ENV: 'development' | 'production' | 'test'
|
NODE_ENV: 'development' | 'production' | 'test'
|
||||||
version: string
|
THEATRE_VERSION: string
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '*.svg' {
|
declare module '*.svg' {
|
||||||
|
|
|
@ -26,7 +26,7 @@ export default async function checkForUpdates() {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
new Request(
|
new Request(
|
||||||
`https://updates.theatrejs.com/updates/${process.env.version}`,
|
`https://updates.theatrejs.com/updates/${process.env.THEATRE_VERSION}`,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
|
|
|
@ -104,7 +104,7 @@ const UpdateDot = styled.div`
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
`
|
`
|
||||||
|
|
||||||
const version: string = process.env.version ?? '0.4.0'
|
const version: string = process.env.THEATRE_VERSION ?? '0.4.0'
|
||||||
|
|
||||||
const untaggedVersion: string = version.match(/^[^\-]+/)![0]
|
const untaggedVersion: string = version.match(/^[^\-]+/)![0]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue