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

Tests: use ES modules #23315

Merged
merged 7 commits into from
Jan 24, 2022
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
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 13 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@
"name": "three",
"version": "0.136.0",
"description": "JavaScript 3D library",
"main": "build/three.js",
"module": "build/three.module.js",
"type": "module",
"main": "./build/three.js",
"module": "./build/three.module.js",
"exports": {
".": {
"import": "./build/three.module.js",
"require": "./build/three.js"
},
"./examples/jsm/*": "./examples/jsm/*.js",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would happen if we renamed this? Say...

"./addons/*": "./examples/jsm/*.js",

Would people be able to this?

import { OrbitControls } from 'three/addons/controls/OrbitControls.js'

And, would the old version stil work?

import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js'

Copy link
Contributor Author

@marcofugaro marcofugaro Jan 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently yes, you can do that, from the docs:

And, would the old version stil work?

Only if you have both of the import aliases in the exports field:

"./addons/*": "./examples/jsm/*.js",
"./examples/jsm/*": "./examples/jsm/*.js",

Otherwise node (or any bundler) throws an error if you're trying to import something that is not in the export fields.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent! That makes thing easy.

What do you think about the name addons? Do you think @drcmda will like it? 🤓

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hahaha I don't mind the name!

I even made a three-addons package back when examples/jsm wasn't a thing 😆

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'll keep it in mind 🙏

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrdoob i do like it 😁

"./src/*": "./src/*.js"
},
"repository": {
"type": "git",
"url": "https://github.com/mrdoob/three.js"
Expand Down Expand Up @@ -41,18 +50,17 @@
"globals": {
"__THREE_DEVTOOLS__": "readonly",
"WebGL2ComputeRenderingContext": "readonly",

"potpack": "readonly",
"fflate": "readonly",
"bodymovin": "readonly",
"OIMO": "readonly",
"Stats": "readonly",
"XRWebGLBinding": "readonly",
"XRWebGLLayer": "readonly",

"GPUShaderStage": "readonly",
"GPUBufferUsage": "readonly",
"GPUTextureUsage": "readonly"
"GPUTextureUsage": "readonly",
"QUnit": "readonly"
},
"rules": {
"no-throw-literal": [
Expand Down Expand Up @@ -123,7 +131,6 @@
"eslint": "^7.32.0",
"eslint-config-mdcs": "^5.0.0",
"eslint-plugin-html": "^6.2.0",
"glob": "^7.2.0",
"rollup": "^2.57.0",
"rollup-plugin-filesize": "^9.1.1",
"rollup-plugin-terser": "^7.0.2",
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/check-coverage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const fs = require( 'fs' );
import fs from 'fs';

// examples
const E = fs.readdirSync( './examples' )
Expand Down
12 changes: 6 additions & 6 deletions test/e2e/puppeteer.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const puppeteer = require( 'puppeteer' );
const handler = require( 'serve-handler' );
const http = require( 'http' );
const pixelmatch = require( 'pixelmatch' );
const jimp = require( 'jimp' );
const fs = require( 'fs' );
import puppeteer from 'puppeteer';
import handler from 'serve-handler';
import http from 'http';
import pixelmatch from 'pixelmatch';
import jimp from 'jimp';
import fs from 'fs';

const port = 1234;
const pixelThreshold = 0.1; // threshold error in one pixel
Expand Down
Loading