Skip to content
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

Switch to ESM where possible, publish release for @minecraft/math #49

Merged
merged 5 commits into from
Jan 9, 2025
Merged
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
3 changes: 2 additions & 1 deletion .github/workflows/release-changes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ jobs:
- name: Publish
run: npm run release -- --token "$NPM_TOKEN" --yes --new
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
REPO_PAT: ${{ secrets.REPO_PAT }}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.turbo
lib
lib-cjs
dist
temp
node_modules
*.tgz
*.tgz
*.zip
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "major",
"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.",
"packageName": "@minecraft/core-build-tasks",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "major",
"comment": "Switch to ESM exclusively. Publish release with artifacts.",
"packageName": "@minecraft/math",
"email": "[email protected]",
"dependentChangeType": "major"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "major",
"comment": "Switch to CJS exclusively, and update to ESLint 9",
"packageName": "eslint-plugin-minecraft-linting",
"email": "[email protected]",
"dependentChangeType": "major"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import {
apiExtractorTask,
cleanTask,
coreLint,
publishReleaseTask,
vitestTask,
} from '@minecraft/core-build-tasks';
import { copyFileSync, createWriteStream, readFileSync } from 'node:fs';
import { resolve } from 'node:path';

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

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

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

// Clean
task('clean', cleanTask(DEFAULT_CLEAN_DIRECTORIES));

// Post-publish
task('postpublish', () => {
return publishReleaseTask({
repoOwner: 'Mojang',
repoName: 'minecraft-scripting-libraries',
message: 'See attached zip for pre-built minecraft-math bundle with type declarations.',
});
});
82 changes: 43 additions & 39 deletions libraries/math/package.json
Original file line number Diff line number Diff line change
@@ -1,42 +1,46 @@
{
"name": "@minecraft/math",
"version": "1.5.2",
"author": "Raphael Landaverde ([email protected])",
"contributors": [
{
"name": "Jake Shirley",
"email": "[email protected]"
"name": "@minecraft/math",
"version": "1.5.2",
"author": "Raphael Landaverde ([email protected])",
"contributors": [
{
"name": "Jake Shirley",
"email": "[email protected]"
}
],
"description": "Math utilities for use with minecraft scripting modules",
"exports": {
"import": "./lib/index.js"
},
"type": "module",
"types": "./lib/types/math-public.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/Mojang/minecraft-scripting-libraries.git",
"directory": "libraries/math"
},
"scripts": {
"build": "just build",
"lint": "just lint",
"test": "just test",
"clean": "just clean",
"postpublish": "just postpublish"
},
"license": "MIT",
"files": [
"dist",
"lib",
"api-report"
],
"peerDependencies": {
"@minecraft/server": "^1.15.0"
},
"devDependencies": {
"@minecraft/server": "^1.15.0",
"@minecraft/core-build-tasks": "*",
"@minecraft/tsconfig": "*",
"just-scripts": "^2.3.3",
"prettier": "^2.8.2",
"vitest": "^0.34.6"
}
],
"description": "Math utilities for use with minecraft scripting modules",
"main": "lib/index.js",
"types": "lib/types/math-public.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/Mojang/minecraft-scripting-libraries.git",
"directory": "libraries/math"
},
"scripts": {
"build": "just build",
"lint": "just lint",
"test": "just test",
"clean": "just clean"
},
"license": "MIT",
"files": [
"dist",
"lib",
"api-report"
],
"peerDependencies": {
"@minecraft/server": "^1.15.0"
},
"devDependencies": {
"@minecraft/server": "^1.15.0",
"@minecraft/core-build-tasks": "*",
"@minecraft/tsconfig": "*",
"just-scripts": "^2.3.2",
"prettier": "^2.8.2",
"vitest": "^0.34.6"
}
}
2 changes: 1 addition & 1 deletion libraries/math/src/general/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

export * from './clamp';
export * from './clamp.js';
4 changes: 2 additions & 2 deletions libraries/math/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

export * from './vector3';
export * from './general';
export * from './vector3/index.js';
export * from './general/index.js';
2 changes: 1 addition & 1 deletion libraries/math/src/vector3/coreHelpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

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

describe('Vector3 operations', () => {
const v1: Vector3 = { x: 1, y: 2, z: 3 };
Expand Down
2 changes: 1 addition & 1 deletion libraries/math/src/vector3/coreHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

import type { Vector2, Vector3 } from '@minecraft/server';
import { clampNumber } from '../general/clamp';
import { clampNumber } from '../general/clamp.js';

/**
* Utilities operating on Vector3 objects. All methods are static and do not modify the input objects.
Expand Down
4 changes: 2 additions & 2 deletions libraries/math/src/vector3/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

export * from './coreHelpers';
export * from './vectorWrapper';
export * from './coreHelpers.js';
export * from './vectorWrapper.js';
4 changes: 2 additions & 2 deletions libraries/math/src/vector3/vectorWrapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import type { Vector3 } from '@minecraft/server';
import { describe, expect, it } from 'vitest';
import { Vector2Utils, Vector3Utils } from './coreHelpers';
import { Vector2Builder, Vector3Builder } from './vectorWrapper';
import { Vector2Utils, Vector3Utils } from './coreHelpers.js';
import { Vector2Builder, Vector3Builder } from './vectorWrapper.js';

/**
* Underlying functionality is validated by coreHelpers tests, primary concern here is consistency of results
Expand Down
2 changes: 1 addition & 1 deletion libraries/math/src/vector3/vectorWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

import type { Vector2, Vector3 } from '@minecraft/server';
import { Vector2Utils, Vector3Utils } from './coreHelpers';
import { Vector2Utils, Vector3Utils } from './coreHelpers.js';

/**
* Vector3 wrapper class which can be used as a Vector3 for APIs on \@minecraft/server which require a Vector,
Expand Down
2 changes: 1 addition & 1 deletion libraries/math/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"compilerOptions": {
"outDir": "lib",
"declarationDir": "temp/types",
"module": "Node16",
"module": "node16",
"moduleResolution": "node16"
}
}
File renamed without changes.
Loading
Loading