Skip to content

Commit

Permalink
feat(jsii): Implement --watch support
Browse files Browse the repository at this point in the history
Re-wrote JSII using the TypeScript compiler services API, integrating
with the `ts.ProgramBuilder` classes so that incremental build is
possible. Additonally, error messages leverage `TypeScript`'s built-in
diagnostic formatter, and enable the rendering of code excerpts with
error messages.
  • Loading branch information
RomainMuller committed Aug 17, 2018
1 parent 62a2e9f commit ff6f7ff
Show file tree
Hide file tree
Showing 94 changed files with 5,285 additions and 6,049 deletions.
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export PATH=node_modules/.bin:$PATH

echo "============================================================================================="
echo "building..."
lerna run build
lerna run build --stream

echo "============================================================================================="
echo "testing..."
lerna run test
lerna run test --stream

touch $BUILD_INDICATOR
1 change: 1 addition & 0 deletions packages/jsii-calc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
},
"scripts": {
"build": "jsii",
"watch": "jsii -w",
"test": "node test/test.calc.js && diff-test test/assembly.jsii .jsii"
},
"bundledDependencies": [
Expand Down
8 changes: 7 additions & 1 deletion packages/jsii-calc/test/assembly.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -2827,9 +2827,15 @@
"kind": "enum",
"members": [
{
"docs": {
"comment": "Normal string expression "
},
"name": "Normal"
},
{
"docs": {
"comment": "Decorated string expression "
},
"name": "Decorated"
}
],
Expand All @@ -2838,5 +2844,5 @@
}
},
"version": "0.6.4",
"fingerprint": "J/33pyDX7y9AI1Vizdu+HEO/87ED05WoSxg41CSYHtw="
"fingerprint": "A6PSlMkLYrySPqgKflMrn2U4DjO6HO+VAJrO66IcSlo="
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public void UnionTypes()
IDictionary<string, object> map = new Dictionary<string, object>();
map["Foo"] = new Multiply(new Number(2), new Number(00));
types.UnionMapProperty = map;
// array
types.UnionArrayProperty = new object[] { "Hello", 123, new Number(3) };
Expand Down Expand Up @@ -571,7 +571,7 @@ public void InterfaceBuilder()
throw new NotImplementedException();
}


[Fact(DisplayName = Prefix + nameof(SyncOverrides_SyncOverrides))]
public void SyncOverrides_SyncOverrides()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,11 @@ private JsiiObject createNative(final String fqn) {
} catch (NoSuchMethodException e) {
throw new JsiiException("Cannot create native object of type "
+ klass.getName()
+ " without a constructor that accepts an InitializationMode argument");
+ " without a constructor that accepts an InitializationMode argument", e);

} catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
throw new JsiiException("Unable to instantiate a new object for FQN " + fqn + ": "
+ e.getMessage());
+ e.getMessage(), e);
}
} catch (ClassNotFoundException e) {
System.err.println("WARNING: Cannot find the class: " + fqn + ". Defaulting to JsiiObject");
Expand Down
2 changes: 2 additions & 0 deletions packages/jsii-pacmak/test/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Generated C# code will have CRLF line endings, making git pretty awkward
.cs eol=crlf
Original file line number Diff line number Diff line change
Expand Up @@ -2827,9 +2827,15 @@
"kind": "enum",
"members": [
{
"docs": {
"comment": "Normal string expression "
},
"name": "Normal"
},
{
"docs": {
"comment": "Decorated string expression "
},
"name": "Decorated"
}
],
Expand All @@ -2838,5 +2844,5 @@
}
},
"version": "0.6.4",
"fingerprint": "J/33pyDX7y9AI1Vizdu+HEO/87ED05WoSxg41CSYHtw="
"fingerprint": "A6PSlMkLYrySPqgKflMrn2U4DjO6HO+VAJrO66IcSlo="
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ namespace Amazon.JSII.Tests.CalculatorNamespace.composition.CompositeOperation
[JsiiEnum(typeof(CompositionStringStyle), "jsii-calc.composition.CompositeOperation.CompositionStringStyle")]
public enum CompositionStringStyle
{
/// <summary>Normal string expression </summary>
[JsiiEnumMember("Normal")]
Normal,
/// <summary>Decorated string expression </summary>
[JsiiEnumMember("Decorated")]
Decorated
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ public void setStringStyle(final software.amazon.jsii.tests.calculator.compositi
*/
@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = "jsii-calc.composition.CompositeOperation.CompositionStringStyle")
public enum CompositionStringStyle {
/**
* Normal string expression
*/
Normal,
/**
* Decorated string expression
*/
Decorated,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2627,8 +2627,14 @@ CompositeOperation
.. py:data:: Normal
Normal string expression
.. py:data:: Decorated
Decorated string expression
Expand Down
30 changes: 15 additions & 15 deletions packages/jsii-spec/lib/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ export interface NamedTypeReference extends TypeReferenceBase {
*/
fqn: string;
}
export function isNamedTypeReference(ref: TypeReference): ref is NamedTypeReference {
return !!(ref as NamedTypeReference).fqn;
export function isNamedTypeReference(ref: TypeReference | undefined): ref is NamedTypeReference {
return ref != null && !!(ref as NamedTypeReference).fqn;
}

/**
Expand All @@ -242,8 +242,8 @@ export interface PrimitiveTypeReference extends TypeReferenceBase {
*/
primitive: PrimitiveType;
}
export function isPrimitiveTypeReference(ref: TypeReference): ref is PrimitiveTypeReference {
return !!(ref as PrimitiveTypeReference).primitive;
export function isPrimitiveTypeReference(ref: TypeReference | undefined): ref is PrimitiveTypeReference {
return ref != null && !!(ref as PrimitiveTypeReference).primitive;
}

/**
Expand All @@ -262,8 +262,8 @@ export interface CollectionTypeReference extends TypeReferenceBase {
elementtype: TypeReference;
};
}
export function isCollectionTypeReference(ref: TypeReference): ref is CollectionTypeReference {
return !!(ref as CollectionTypeReference).collection;
export function isCollectionTypeReference(ref: TypeReference | undefined): ref is CollectionTypeReference {
return ref != null && !!(ref as CollectionTypeReference).collection;
}

/**
Expand All @@ -281,8 +281,8 @@ export interface UnionTypeReference extends TypeReferenceBase {
types: TypeReference[];
}
}
export function isUnionTypeReference(ref: TypeReference): ref is UnionTypeReference {
return !!(ref as UnionTypeReference).union;
export function isUnionTypeReference(ref: TypeReference | undefined): ref is UnionTypeReference {
return ref != null && !!(ref as UnionTypeReference).union;
}

/**
Expand Down Expand Up @@ -497,8 +497,8 @@ export interface ClassType extends TypeBase {
interfaces?: NamedTypeReference[];
}

export function isClassType(type: Type): type is ClassType {
return type.kind === TypeKind.Class;
export function isClassType(type: Type | undefined): type is ClassType {
return type != null && type.kind === TypeKind.Class;
}

export interface InterfaceType extends TypeBase {
Expand Down Expand Up @@ -529,8 +529,8 @@ export interface InterfaceType extends TypeBase {
datatype?: boolean;
}

export function isInterfaceType(type: Type): type is InterfaceType {
return type.kind === TypeKind.Interface;
export function isInterfaceType(type: Type | undefined): type is InterfaceType {
return type != null && type.kind === TypeKind.Interface;
}

/**
Expand All @@ -555,14 +555,14 @@ export interface EnumType extends TypeBase {
members: EnumMember[];
}

export function isEnumType(type: Type): type is EnumType {
return type.kind === TypeKind.Enum;
export function isEnumType(type: Type | undefined): type is EnumType {
return type != null && type.kind === TypeKind.Enum;
}

/**
* Return whether this type is a class or interface type
*/
export function isClassOrInterfaceType(type: Type): type is (InterfaceType | ClassType) {
export function isClassOrInterfaceType(type: Type | undefined): type is (InterfaceType | ClassType) {
return isClassType(type) || isInterfaceType(type);
}

Expand Down
63 changes: 0 additions & 63 deletions packages/jsii-spec/test/tsconfig.json

This file was deleted.

4 changes: 2 additions & 2 deletions packages/jsii/.npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Don't include original .ts files when doing `npm pack`
*.ts
*
!*.js
!*.d.ts
Loading

0 comments on commit ff6f7ff

Please sign in to comment.