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

Dependency fix on typescript CLI #1180

Merged
merged 14 commits into from
Sep 3, 2024

Conversation

reebayroo
Copy link
Contributor

@reebayroo reebayroo commented Aug 28, 2024

This PR contains the following:

  • Fixing the support for Http and File dependencies on the dependencies property of morphir.json file
  • Fixing the localDependencies compatibility
  • Integration tests for local and dependencies
  • Unit tests for the dependencies module

Terms

THIS SOFTWARE IS CONTRIBUTED SUBJECT TO THE TERMS OF THE TERMS OF THE CCLA DATED 2017-11-07 WITH FINOS/LINUX FOUNDATION (FORMERLY THE SYMPHONY SOFTWARE FOUNDATION CCLA).

THIS SOFTWARE IS LICENSED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY WARRANTY OF NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THIS SOFTWARE MAY BE REDISTRIBUTED TO OTHERS ONLY BY EFFECTIVELY USING THIS OR ANOTHER EQUIVALENT DISCLAIMER IN ADDITION TO ANY OTHER REQUIRED LICENSE TERMS.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unit test for the dependencies file

@@ -9,7 +11,7 @@ import { ResultAsync } from "neverthrow";
const parseDataUrl = require("data-urls");
const fsReadFile = util.promisify(fs.readFile);

const DataUrl = z.string().trim().transform((val, ctx) => {
export const DataUrl = z.string().trim().transform((val, ctx) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exposing this objects so they can be unit tested

@@ -21,7 +23,7 @@ const DataUrl = z.string().trim().transform((val, ctx) => {
return parsed;
});

const FileUrl = z.string().trim().url().transform((val, ctx) => {
export const FileUrl = z.string().trim().url().transform((val, ctx) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exposing this objects so they can be unit tested

owner: z.string(),
repo: z.string(),
baseUrl: z.string().optional()
});

const GithubConfig = z.union([GithubData, z.string()]);

const DependencySettings = z.union([DataUrl, FileUrl, z.string().trim()])
// const DependencySettings = z.union([DataUrl, FileUrl, z.string().trim()])
const DependencySettings = z.string().trim();
const Dependencies = z.array(DependencySettings).default([]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the fix for the Dependencies

@@ -112,7 +129,7 @@ export async function loadAllDependencies(config: DependencyConfig) {
const finalResults = await Promise.all(results);
return finalResults.flatMap((result) => {
if (result.isOk()) {
console.error("Successfully loaded dependency", result.value.dependency)
console.info("Successfully loaded dependency", result.value.dependency)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

removing error messages for debugging purposes

@reebayroo reebayroo marked this pull request as ready for review September 1, 2024 12:57
@@ -46,7 +46,8 @@ async function make(
const dependencyConfig = DependencyConfig.parse({
dependencies: morphirJson.dependencies,
localDependencies: morphirJson.localDependencies,
includes: includes
includes: includes,
projectDir: projectDir
})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ProjectDir preserves the project directory option passed through the command line

expect(fileData).toBeUndefined
});
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The dependencies test helps enforce the business logic of those types, ie the Url type does not support anything but ftp and http(s)

import { Readable } from "stream";
import { ResultAsync } from "neverthrow";

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Organizing imports

url?: URL,

}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Used by LocalFile to keep track of the different forms of a path

import { decode, labelToName } from "whatwg-encoding";
import { z } from "zod";
import { fetchUriToJson } from "./get-uri-wrapper";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

get-uri-wrapper works a facade so HTTP types can be mocked.

@@ -214,7 +214,7 @@ async function testUnit(cb) {
}

async function compileCli2Ts() {
src('./cli2/*.ts').pipe(cliTsProject()).pipe(dest('./cli2/lib/'))
src(['./cli2/*.ts', '!./cli2/*.test.ts' ]).pipe(cliTsProject()).pipe(dest('./cli2/lib/'))
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Excluding unit tests from being copied to lib folder, otherwise the tes.js files will run , and fail, during integration tests

@@ -18,6 +18,7 @@
"ncc-morphir": "ncc build cli/morphir.js -o dist/morphir",
"ncc-morphir-server": "ncc build cli/morphir-elm-develop.js -o dist/morphir-server",
"build": "gulp && npm run ncc-morphir && npm run ncc-morphir-server && npx jest && gulp test",
"build-cli2": "gulp buildCLI2",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

To speed up process of running integration tests

Copy link
Member

@DamianReeves DamianReeves left a comment

Choose a reason for hiding this comment

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

LGTM

@DamianReeves DamianReeves merged commit b7c43d6 into finos:main Sep 3, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants