Skip to content

Commit 55a4e19

Browse files
authored
Switch to ESM where possible, publish release for @minecraft/math (#49)
* Switch to ESM exclusively. This involves updating downstream packages to specify "type: module" in their package.json, and having the upstream core-build-tasks package support both ESM and CJS due to just.js requiring commonjs for the most part. Also updates ESLint to latest, including flat configs, and updates the rule tester for better integration with vitest. * Update core-build-tasks to partially bundle in order to handle ESM only dependencies from commonjs invocations. Add release publishing task to core-build-tasks and integrate it into minecraft math so that the pre-built bundle is included in releases. Integrate this release publish into the release pipeline.
1 parent 1551e02 commit 55a4e19

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+4511
-3445
lines changed

.github/workflows/release-changes.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ jobs:
3434
- name: Publish
3535
run: npm run release -- --token "$NPM_TOKEN" --yes --new
3636
env:
37-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
37+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
38+
REPO_PAT: ${{ secrets.REPO_PAT }}

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
.turbo
22
lib
3+
lib-cjs
34
dist
45
temp
56
node_modules
6-
*.tgz
7+
*.tgz
8+
*.zip
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "major",
3+
"comment": "Export both ESM and CJS, but exclusively use CJS for just task configuration. Pre-bundle most dependencies to deal with ESM exclusive dependencies.\nTo leverage the new tasks, use a `just.config.cts` file to rely on CommonJS imports.",
4+
"packageName": "@minecraft/core-build-tasks",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "major",
3+
"comment": "Switch to ESM exclusively. Publish release with artifacts.",
4+
"packageName": "@minecraft/math",
5+
"email": "[email protected]",
6+
"dependentChangeType": "major"
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "major",
3+
"comment": "Switch to CJS exclusively, and update to ESLint 9",
4+
"packageName": "eslint-plugin-minecraft-linting",
5+
"email": "[email protected]",
6+
"dependentChangeType": "major"
7+
}

libraries/math/just.config.ts libraries/math/just.config.cts

+21-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ import {
55
apiExtractorTask,
66
cleanTask,
77
coreLint,
8+
publishReleaseTask,
89
vitestTask,
910
} from '@minecraft/core-build-tasks';
11+
import { copyFileSync, createWriteStream, readFileSync } from 'node:fs';
12+
import { resolve } from 'node:path';
1013

1114
const isOnlyBuild = argv()._.findIndex(arg => arg === 'test') === -1;
1215

@@ -18,8 +21,16 @@ task('typescript', tscTask());
1821
task('api-extractor-local', apiExtractorTask('./api-extractor.json', isOnlyBuild /* localBuild */));
1922
task('bundle', () => {
2023
execSync(
21-
'npx esbuild ./lib/index.js --bundle --outfile=dist/minecraft-math.js --format=esm --sourcemap --external:@minecraft/server',
24+
'npx esbuild ./lib/index.js --bundle --outfile=dist/minecraft-math.js --format=esm --sourcemap --external:@minecraft/server'
2225
);
26+
// Copy over type definitions and rename
27+
const officialTypes = JSON.parse(readFileSync('./package.json', 'utf-8'))['types'];
28+
if (!officialTypes) {
29+
// Has the package.json been restructured?
30+
throw new Error('The package.json file does not contain a "types" field. Unable to copy types to bundle.');
31+
}
32+
const officialTypesPath = resolve(officialTypes);
33+
copyFileSync(officialTypesPath, './dist/minecraft-math.d.ts');
2334
});
2435
task('build', series('typescript', 'api-extractor-local', 'bundle'));
2536

@@ -30,3 +41,12 @@ task('test', series('api-extractor-validate', 'vitest'));
3041

3142
// Clean
3243
task('clean', cleanTask(DEFAULT_CLEAN_DIRECTORIES));
44+
45+
// Post-publish
46+
task('postpublish', () => {
47+
return publishReleaseTask({
48+
repoOwner: 'Mojang',
49+
repoName: 'minecraft-scripting-libraries',
50+
message: 'See attached zip for pre-built minecraft-math bundle with type declarations.',
51+
});
52+
});

libraries/math/package.json

+43-39
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,46 @@
11
{
2-
"name": "@minecraft/math",
3-
"version": "1.5.2",
4-
"author": "Raphael Landaverde ([email protected])",
5-
"contributors": [
6-
{
7-
"name": "Jake Shirley",
8-
"email": "[email protected]"
2+
"name": "@minecraft/math",
3+
"version": "1.5.2",
4+
"author": "Raphael Landaverde ([email protected])",
5+
"contributors": [
6+
{
7+
"name": "Jake Shirley",
8+
"email": "[email protected]"
9+
}
10+
],
11+
"description": "Math utilities for use with minecraft scripting modules",
12+
"exports": {
13+
"import": "./lib/index.js"
14+
},
15+
"type": "module",
16+
"types": "./lib/types/math-public.d.ts",
17+
"repository": {
18+
"type": "git",
19+
"url": "https://github.com/Mojang/minecraft-scripting-libraries.git",
20+
"directory": "libraries/math"
21+
},
22+
"scripts": {
23+
"build": "just build",
24+
"lint": "just lint",
25+
"test": "just test",
26+
"clean": "just clean",
27+
"postpublish": "just postpublish"
28+
},
29+
"license": "MIT",
30+
"files": [
31+
"dist",
32+
"lib",
33+
"api-report"
34+
],
35+
"peerDependencies": {
36+
"@minecraft/server": "^1.15.0"
37+
},
38+
"devDependencies": {
39+
"@minecraft/server": "^1.15.0",
40+
"@minecraft/core-build-tasks": "*",
41+
"@minecraft/tsconfig": "*",
42+
"just-scripts": "^2.3.3",
43+
"prettier": "^2.8.2",
44+
"vitest": "^0.34.6"
945
}
10-
],
11-
"description": "Math utilities for use with minecraft scripting modules",
12-
"main": "lib/index.js",
13-
"types": "lib/types/math-public.d.ts",
14-
"repository": {
15-
"type": "git",
16-
"url": "https://github.com/Mojang/minecraft-scripting-libraries.git",
17-
"directory": "libraries/math"
18-
},
19-
"scripts": {
20-
"build": "just build",
21-
"lint": "just lint",
22-
"test": "just test",
23-
"clean": "just clean"
24-
},
25-
"license": "MIT",
26-
"files": [
27-
"dist",
28-
"lib",
29-
"api-report"
30-
],
31-
"peerDependencies": {
32-
"@minecraft/server": "^1.15.0"
33-
},
34-
"devDependencies": {
35-
"@minecraft/server": "^1.15.0",
36-
"@minecraft/core-build-tasks": "*",
37-
"@minecraft/tsconfig": "*",
38-
"just-scripts": "^2.3.2",
39-
"prettier": "^2.8.2",
40-
"vitest": "^0.34.6"
41-
}
4246
}

libraries/math/src/general/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
export * from './clamp';
4+
export * from './clamp.js';

libraries/math/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
export * from './vector3';
5-
export * from './general';
4+
export * from './vector3/index.js';
5+
export * from './general/index.js';

libraries/math/src/vector3/coreHelpers.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import { Vector2, Vector3 } from '@minecraft/server';
55
import { describe, expect, it } from 'vitest';
6-
import { Vector2Utils, VECTOR3_LEFT, VECTOR3_UP, Vector3Utils } from './coreHelpers';
6+
import { Vector2Utils, VECTOR3_LEFT, VECTOR3_UP, Vector3Utils } from './coreHelpers.js';
77

88
describe('Vector3 operations', () => {
99
const v1: Vector3 = { x: 1, y: 2, z: 3 };

libraries/math/src/vector3/coreHelpers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the MIT License.
33

44
import type { Vector2, Vector3 } from '@minecraft/server';
5-
import { clampNumber } from '../general/clamp';
5+
import { clampNumber } from '../general/clamp.js';
66

77
/**
88
* Utilities operating on Vector3 objects. All methods are static and do not modify the input objects.

libraries/math/src/vector3/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
export * from './coreHelpers';
5-
export * from './vectorWrapper';
4+
export * from './coreHelpers.js';
5+
export * from './vectorWrapper.js';

libraries/math/src/vector3/vectorWrapper.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
import type { Vector3 } from '@minecraft/server';
55
import { describe, expect, it } from 'vitest';
6-
import { Vector2Utils, Vector3Utils } from './coreHelpers';
7-
import { Vector2Builder, Vector3Builder } from './vectorWrapper';
6+
import { Vector2Utils, Vector3Utils } from './coreHelpers.js';
7+
import { Vector2Builder, Vector3Builder } from './vectorWrapper.js';
88

99
/**
1010
* Underlying functionality is validated by coreHelpers tests, primary concern here is consistency of results

libraries/math/src/vector3/vectorWrapper.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the MIT License.
33

44
import type { Vector2, Vector3 } from '@minecraft/server';
5-
import { Vector2Utils, Vector3Utils } from './coreHelpers';
5+
import { Vector2Utils, Vector3Utils } from './coreHelpers.js';
66

77
/**
88
* Vector3 wrapper class which can be used as a Vector3 for APIs on \@minecraft/server which require a Vector,

libraries/math/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"compilerOptions": {
66
"outDir": "lib",
77
"declarationDir": "temp/types",
8-
"module": "Node16",
8+
"module": "node16",
99
"moduleResolution": "node16"
1010
}
1111
}
File renamed without changes.

0 commit comments

Comments
 (0)