Skip to content

Commit

Permalink
refactor(build): fix build issues
Browse files Browse the repository at this point in the history
refactor(build): fix build issues
  • Loading branch information
timofei-iatsenko committed Jan 13, 2023
1 parent c199607 commit 3df791f
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 79 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"lint:types": "tsc",
"lint:eslint": "eslint packages",
"lint:all": "yarn lint:eslint && yarn lint:types",
"release:build": "node -r @swc-node/register ./scripts/build/index.ts",
"release:test": "node ./scripts/test.js",
"release:build": "node -r @swc-node/register ./scripts/build/index.ts",
"release:test": "node -r @swc-node/register ./scripts/test.ts",
"version:next": "lerna version --exact --force-publish --no-private --preid next --create-release github --conventional-commits --conventional-prerelease --yes",
"version:latest": "lerna version --exact --force-publish --no-private --create-release github --conventional-commits --yes",
"release:latest": "lerna publish from-package --contents build --dist-tag latest --yes",
Expand Down
4 changes: 0 additions & 4 deletions packages/core/src/dev/index.ts

This file was deleted.

18 changes: 0 additions & 18 deletions packages/core/src/dev/loadLocaleData.test.ts

This file was deleted.

10 changes: 0 additions & 10 deletions packages/core/src/dev/loadLocaleData.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/core/src/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { interpolate, UNICODE_REGEX } from "./context"
import { isString, isFunction } from "./essentials"
import { date, number } from "./formats"
import * as icu from "./dev"
import { compileMessage } from "./compile"
import { EventEmitter } from "./eventEmitter"
import type {PluralCategory} from "make-plural"

Expand Down Expand Up @@ -206,7 +206,7 @@ export class I18n extends EventEmitter<Events> {

if (process.env.NODE_ENV !== "production") {
translation = isString(translation)
? icu.compile(translation)
? compileMessage(translation)
: translation
}

Expand Down
17 changes: 0 additions & 17 deletions scripts/build/__snapshots__/packaging.spec.ts.snap

This file was deleted.

63 changes: 46 additions & 17 deletions scripts/build/packaging.spec.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
import {fixPackageEntries, makeRelativeToBuildPath} from "./packaging"
import { fixPackageEntries, makeRelativeToBuildPath } from "./packaging"

describe('makeRelativeToBuildPath', () => {
it('should remove /build from the path', () => {
expect(makeRelativeToBuildPath('./build/cjs/index.js'))
.toBe('cjs/index.js')
describe("makeRelativeToBuildPath", () => {
it("should remove /build from the path", () => {
expect(makeRelativeToBuildPath("./build/cjs/index.js")).toBe("./cjs/index.js")

expect(makeRelativeToBuildPath('build/cjs/index.js'))
.toBe('cjs/index.js')
expect(makeRelativeToBuildPath("build/cjs/index.js")).toBe("./cjs/index.js")

expect(makeRelativeToBuildPath('./prefix/build/cjs/index.js'))
.toBe('./prefix/build/cjs/index.js')
expect(makeRelativeToBuildPath("./prefix/build/cjs/index.js")).toBe(
"./prefix/build/cjs/index.js"
)
})

it('should keep path without build inside intact', () => {
expect(makeRelativeToBuildPath('cjs/index.js'))
.toBe('cjs/index.js')
it("should keep path without build inside intact", () => {
expect(makeRelativeToBuildPath("cjs/index.js")).toBe("cjs/index.js")
})
})


describe("fixPackageEntries", () => {
it('should replace entries pointing to build, to relative', () => {
const actual = fixPackageEntries(JSON.parse(`
it("should replace entries pointing to build, to relative", () => {
const actual = fixPackageEntries(
JSON.parse(`
{
"name": "@lingui/core",
"main": "./build/index.js",
Expand All @@ -35,8 +33,39 @@ describe("fixPackageEntries", () => {
"./package.json": "./package.json"
}
}
`))
`)
)

expect(actual).toMatchInlineSnapshot(`
Object {
"exports": Object {
".": Object {
"import": "./esm/index.js",
"require": "./index.js",
},
"./package.json": "./package.json",
},
"main": "./index.js",
"module": "./esm/index.js",
"name": "@lingui/core",
"types": "./cjs/index.d.ts",
}
`)
})
it("should not add empty exports: {}", () => {
const actual = fixPackageEntries(
JSON.parse(`
{
"name": "@lingui/core"
}
`)
)

expect(actual).toMatchSnapshot();
expect(actual).toMatchInlineSnapshot(`
Object {
"exports": undefined,
"name": "@lingui/core",
}
`)
})
})
8 changes: 4 additions & 4 deletions scripts/build/packaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function getTarOptions(tgzName: string, packageName: string) {

export function makeRelativeToBuildPath(path: string) {
if (path.startsWith('build/') || path.startsWith('./build')) {
return nodePath.relative('build/', path)
return "./" + nodePath.relative('build/', path)
}

return path
Expand Down Expand Up @@ -92,15 +92,15 @@ export function fixPackageEntries(packageJson) {
})
}

return {...newPackageJson, exports: newExports}
return {...newPackageJson, exports: exports ? newExports : undefined}
}

async function makeBuildPackageJson(srcPath: string, dstPath: string) {
const srcPackageJson = await fsPromises.readFile(srcPath)
const newFile = fixPackageEntries(JSON.parse(srcPackageJson.toString()))
asyncMkDirP(nodePath.dirname(dstPath));
await asyncMkDirP(nodePath.dirname(dstPath));

await fsPromises.writeFile(dstPath, JSON.stringify(newFile))
await fsPromises.writeFile(dstPath, JSON.stringify(newFile, undefined, " "))

}

Expand Down
11 changes: 6 additions & 5 deletions scripts/test.js → scripts/test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
const argv = require("minimist")(process.argv.slice(2))

const fs = require("fs")
const path = require("path")
const { execSync } = require("child_process")
import * as fs from "fs"
import * as path from "path"
import {execSync} from "child_process"

const chalk = require("chalk")
const ora = require("ora")

const EXAMPLES_DIR = path.resolve("examples")

function listDirs(dir) {
function listDirs(dir: string) {
return fs
.readdirSync(dir)
.filter(dirname => fs.lstatSync(path.join(dir, dirname)).isDirectory())
Expand All @@ -26,7 +27,7 @@ const logHeading = message => console.log(chalk.bold("\n" + message + "\n"))

if (!argv["skip-build"]) {
logHeading("Build packages")
execSync("node scripts/build", { stdio: "inherit" })
execSync("yarn release:build", { stdio: "inherit" })
}

// TODO: Replace yalc with verdaccio
Expand Down

0 comments on commit 3df791f

Please sign in to comment.