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

Update sylvester typings to be a cjs module #13627

Closed
wants to merge 4 commits into from

Conversation

connor4312
Copy link
Contributor

Please fill in this template.

  • Make your PR against the master branch.
  • Use a meaningful title for the pull request. Include the name of the package modified.
  • Test the change in your own code. (Compile and run.)
  • Follow the advice from the readme.
  • Avoid common mistakes.
  • Run tsc without errors.
  • Run npm run lint package-name if a tslint.json is present.

If changing an existing definition:

  • Provide a URL to documentation or source code which provides context for the suggested changes: (see a bit below)
  • Increase the version number in the header if appropriate.
  • If you are making substantial changes, consider adding a tslint.json containing { "extends": "../tslint.json" }.

Sylvester is exported as a CommonJS module and, while it declares some globals, there are requests to remove them and most usage in TypeScript will prefer to use it as a CommonJS module. I did not see a way to provide both global and module exports in a typings file, so I favored converting it to a CommonJS typing and removing the global exports.

I've also updated it to the recommended modern linting rules and best practices.

@dt-bot
Copy link
Member

dt-bot commented Dec 30, 2016

sylvester/index.d.ts

to author (@StephaneAlie). Could you review this PR?
👍 or 👎?

Checklist

  • pass the Travis CI test?

@ghost
Copy link

ghost commented Dec 30, 2016

As-is this PR would break compilation for people using globals.
You can fix it like so:

// No `declare namespace sylvester` wrapper

export class Vector { ... }
export class Matrix { ... }
export class Line { ... }
export class Plane { ... }

// You probably meant "namespace" and not "interface".
export namespace Sylvester {
    // `require("sylvester").Sylvester.version` doesn't work for me, but `require("sylvester").Sylvester.approxPrecision` does.
    export const precision: number;
    export const approxPrecision: number;
}

// Re-export as globals.
import * as s from "sylvester";

declare global {
    const Vector: typeof s.Vector;
    type Vector = s.Vector;
    const Matrix: typeof s.Matrix;
    type Matrix = s.Matrix;
    const Line: typeof s.Line;
    type Line = s.Line;
    const Plane: typeof s.Plane;
    type Plane = s.Plane;
    const Sylvester: typeof s.Sylvester;

    // Assuming these are global-only functions
    declare function $V(elements: Vector|Array<number>): Vector;
    ...
    declare function $P(anchor: Array<number>|Vector, v1: Array<number>|Vector, v2: Array<number>|Vector): Plane;
}

Then have both sylvester-tests.ts and a sylvester-global-tests.ts which tests the globals ($V through $P, and tests that Vector is available globally.)
Also, since you're changing the whole thing, please add a tslint.json containing { "extends": "../tslint.json" }.

@ghost ghost added the Revision needed This PR needs code changes before it can be merged. label Dec 30, 2016
@connor4312
Copy link
Contributor Author

Thanks for the thorough review, I've updated the typings 😄

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Leaving the rest for @StephaneAlie

}

export namespace Sylvester {
export const version: string;
Copy link

Choose a reason for hiding this comment

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

Can you verify that this exists?

@@ -7,819 +7,781 @@
// Vector and Matrix mathematics modules for JavaScript
// Copyright (c) 2007 James Coglan

declare module Sylvester {
interface VectorStatic {
export class Vector {
Copy link

Choose a reason for hiding this comment

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

Reduce indentation (no longer nested)

@ghost ghost added Awaiting reviewer feedback and removed Revision needed This PR needs code changes before it can be merged. labels Dec 30, 2016
Copy link

@StephaneAlie StephaneAlie left a comment

Choose a reason for hiding this comment

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

That looks a lot cleaner than what I had, thanks for the update!

@@ -1,4 +1,7 @@
interface IAny {
import { Line, Matrix, Plane, Vector } from 'sylvester';
import 'sylvester';
Copy link
Member

Choose a reason for hiding this comment

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

Any reason you need this?

@ghost
Copy link

ghost commented Jan 5, 2017

@connor4312 Please fix the merge conflicts.

@ghost ghost added Revision needed This PR needs code changes before it can be merged. and removed Awaiting reviewer feedback labels Jan 7, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Jan 19, 2017

@connor4312 the test file name needs to be changed to test\global.ts

@zhengbli
Copy link
Contributor

@connor4312 can you update according to the reviews? Thank you!

@jramsay
Copy link
Contributor

jramsay commented Mar 1, 2017

@connor4312: if you can take care of the remaining changes from code review comments we'll be able to merge this PR. Thanks!

@yuit
Copy link
Contributor

yuit commented Mar 7, 2017

@connor4312 Thanks for your contribution. This PR has unaddressed comments and cannot be merged in at the time being. For housekeeping purposes we are closing stale PRs. If you'd still like to merge this code in, please open a new PR that has been merged and rebased with the master branch.

@yuit yuit closed this Mar 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Revision needed This PR needs code changes before it can be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants