Skip to content

Commit

Permalink
R!! Use new TypeScript5 API in addons package (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamora authored May 23, 2023
2 parents 98a29fc + fa18317 commit af50667
Show file tree
Hide file tree
Showing 12 changed files with 1,940 additions and 2,866 deletions.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,33 +50,33 @@
},
"devDependencies": {
"@nrwl/nx-cloud": "latest",
"@types/node": "16",
"@swc/core": "^1.3.57",
"@swc/jest": "^0.2.26",
"@types/node": "16",
"cross-env": "^7.0.3",
"eslint": "^8.40.0",
"eslint-config-prettier": "^8.8.0",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jest": "^27.2.1",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-testing-library": "^5.10.3",
"eslint-plugin-testing-library": "^5.11.0",
"husky": "^8.0.3",
"jest": "^29.5.0",
"lerna": "^6.6.2",
"license-check-and-add": "^4.0.5",
"lint-staged": "^13.2.2",
"memfs": "3.4.x",
"nx": "15.3.x",
"memfs": "3.5.x",
"nx": "16.1.x",
"prettier": "^2.8.8",
"regenerator-runtime": "0.13.11",
"rimraf": "5.0.0",
"ts-jest": "^29.1.0",
"ts-node": "10.9.x",
"typescript": "4.7.x"
"typescript": "5.0.x"
},
"engines": {
"node": ">=16.x",
"yarn": ">=1.22.x"
"node": "16 || 18",
"yarn": "1.22.x"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const createClientTransformer = ({ libPath, functionsDir }: Transformatio
}

if (ts.isImportDeclaration(node)) {
return undefined;
return node;
}

if (!isTransformable(node)) {
Expand All @@ -41,15 +41,15 @@ export const createClientTransformer = ({ libPath, functionsDir }: Transformatio

const decorations = getDecoration(sf, node, DECORATOR_NAME);
if (!isNodeExported(node) || !decorations) {
return undefined;
return node;
}

const [transformedNode, isServiceFunction] = transformNode(node, sf, decorations);
hasServiceFunctions = hasServiceFunctions || isServiceFunction;
return transformedNode ?? node;
};

sf = ts.visitNode(sf, visitor);
sf = ts.visitNode(sf, visitor, ts.isSourceFile);
if (hasServiceFunctions) {
if (!hasInvokeImport(sf, libPath, NAMED_IMPORTS)) {
sf = ts.factory.updateSourceFile(sf, [getImportInvoke(libPath, NAMED_IMPORTS), ...sf.statements]);
Expand Down Expand Up @@ -94,7 +94,6 @@ export const hasInvokeImport = (sf: ts.SourceFile, libPath: string, namedImports

export const getImportInvoke = (libPath: string, namedImports: string[]): ts.Statement => {
return ts.factory.createImportDeclaration(
undefined,
undefined,
ts.factory.createImportClause(
false,
Expand Down
1 change: 0 additions & 1 deletion packages/addons/addons/magellan-shared/node-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ export const getFunctionName = (node: ts.VariableStatement | ts.FunctionDeclarat

export const createInvokeImport = (libPath: string, namedImports: string[]): ts.Statement => {
return factory.createImportDeclaration(
undefined,
undefined,
factory.createImportClause(
false,
Expand Down
10 changes: 6 additions & 4 deletions packages/addons/addons/magellan-shared/transform-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ export const transformInvocableFunction = (
const parameters = getObjectLiteralsOfNode(node);
return factory.updateFunctionDeclaration(
node,
node.decorators,
node.modifiers,
node.asteriskToken,
node.name,
Expand All @@ -133,7 +132,6 @@ export const transformLocalServerFunction = (node: ts.Node): ts.Node => {
const newParameters = createObjectifiedParameter(node);
return factory.updateFunctionDeclaration(
node,
node.decorators,
node.modifiers,
node.asteriskToken,
node.name,
Expand Down Expand Up @@ -178,9 +176,13 @@ const createObjectifiedParameter = (node: ts.Node): ts.ParameterDeclaration[] =>
parameters?.map(p => factory.createBindingElement(undefined, undefined, factory.createIdentifier(p.name.getText()), undefined)) ?? []
);
const typeLiteral = factory.createTypeLiteralNode(
parameters?.map(p => factory.createPropertySignature(p.modifiers, p.name.getText(), p.questionToken, p.type))
parameters?.map(p => factory.createPropertySignature(
// TODO: API clash ModifierLike[] (new) vs. Modifier[] (old)
p.modifiers as any,
p.name.getText(),
p.questionToken, p.type))
);
return [factory.createParameterDeclaration(undefined, undefined, undefined, bindingPattern, undefined, typeLiteral, undefined)];
return [factory.createParameterDeclaration(undefined, undefined, bindingPattern, undefined, typeLiteral, undefined)];
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const createServerTransformer = ({ functionsDir }: TransformationArgument
return ts.visitEachChild(node, visitor, ctx);
};

return ts.visitNode(sf, visitor);
return ts.visitNode(sf, visitor, ts.isSourceFile);
};
};
return platformTransformerFactory;
Expand Down
8 changes: 4 additions & 4 deletions packages/addons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@
"dependencies": {
"@quatico/magellan-client": "^0.3.0",
"@quatico/magellan-server": "^0.3.0",
"@quatico/websmith-api": "0.3.5",
"typescript": "4.7.x"
"@quatico/websmith-api": "0.4.0",
"typescript": "5.0.x"
},
"engines": {
"node": "=16 || =18",
"yarn": "=1.22.x"
"node": "16 || 18",
"yarn": "1.22.x"
}
}
14 changes: 7 additions & 7 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@
"dependencies": {
"@quatico/magellan-client": "^0.3.0",
"@quatico/magellan-server": "^0.3.0",
"@quatico/websmith-api": "0.3.5",
"@quatico/websmith-compiler": "0.3.5",
"@quatico/websmith-core": "0.3.5",
"@quatico/websmith-api": "0.4.0",
"@quatico/websmith-compiler": "0.4.0",
"@quatico/websmith-core": "0.4.0",
"commander": "^9.4.1",
"minimist": "1.2.7",
"ts-node": "^10.9.1",
"typescript": "4.7.x"
"ts-node": "10.9.x",
"typescript": "5.0.x"
},
"devDependencies": {
"@swc/core": "^1.3.16",
Expand All @@ -75,8 +75,8 @@
"ts-jest": "^29.0.3"
},
"engines": {
"node": "=16 || =18",
"yarn": "=1.22.x"
"node": "16 || 18",
"yarn": "1.22.x"
},
"nx": {
"outputs": [
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@
"prettier": "^2.8.8",
"rimraf": "^5.0.0",
"ts-jest": "^29.1.0",
"typescript": "4.7.x"
"typescript": "5.0.x"
}
}
6 changes: 3 additions & 3 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@
"supertest": "^6.3.3",
"ts-jest": "^29.1.0",
"ts-node": "10.9.x",
"typescript": "4.7.x"
"typescript": "5.0.x"
},
"engines": {
"node": "=16 || =18",
"yarn": "=1.22.x"
"node": "16 || 18",
"yarn": "1.22.x"
}
}
2 changes: 1 addition & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@
"prettier": "^2.7.1",
"rimraf": "^3.0.2",
"ts-jest": "^29.0.3",
"typescript": "4.7.x"
"typescript": "5.0.x"
}
}
6 changes: 3 additions & 3 deletions packages/test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@
"memfs": "3.4.x",
"prettier": "^2.8.8",
"rimraf": "^5.0.0",
"typescript": "4.7.x"
"typescript": "5.0.x"
},
"engines": {
"node": "=16 || =18",
"yarn": "=1.22.x"
"node": "16 || 18",
"yarn": "1.22.x"
}
}
Loading

0 comments on commit af50667

Please sign in to comment.