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

feat(deno): support esbuild #310

Merged
merged 12 commits into from
Jul 19, 2023
211 changes: 210 additions & 1 deletion e2e/deno-e2e/tests/deno-integrated.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ console.log('123');
const project = readJson(`apps/${appName}-tagged/project.json`);
expect(project.tags).toEqual(['scope:deno', 'type:app']);
}, 120_000);
});
});
charsleysa marked this conversation as resolved.
Show resolved Hide resolved

describe('library', () => {
it('should create deno lib', async () => {
Expand Down Expand Up @@ -484,5 +484,214 @@ console.log(${fnName}())`
});
await promisifiedTreeKill(p.pid, 'SIGKILL');
}, 120_000);

it('should be able to use import alias of lib in app for build', async () => {
const fnName = names(libName).propertyName;
updateFile(
`apps/${appName}/src/main.ts`,
`import { ${fnName} } from '@proj/${libName}'

console.log(${fnName}())`
);

const result = await runNxCommandAsync(`build ${appName}`);
expect(result.stdout).toContain(
`Successfully ran target build for project ${appName}`
);
expect(workspaceFileExists(`dist/apps/${appName}/main.js`)).toBeTruthy();
}, 120_000);
});

describe('--bundler deno_emit', () => {
const bundlerAppName = uniq('deno-app-deno-emit');
const bundlerLibName = uniq('deno-lib-deno-emit');

it('should create deno app', async () => {
await runNxCommandAsync(`generate @nx/deno:app ${bundlerAppName} --bundler deno_emit`);
expect(workspaceFileExists(`apps/${bundlerAppName}/src/main.ts`)).toBeTruthy();
}, 120_000);

it('should build deno app', async () => {
const result = await runNxCommandAsync(`build ${bundlerAppName}`);
expect(result.stdout).toContain(
`Successfully ran target build for project ${bundlerAppName}`
);
expect(workspaceFileExists(`dist/apps/${bundlerAppName}/main.js`)).toBeTruthy();
}, 120_000);

it('should build deno app w/assets', async () => {
// Workspace ignore files
writeFileSync(join(tmpProjPath(), '.gitignore'), `git-ignore.hbs`);
writeFileSync(join(tmpProjPath(), '.nxignore'), `nx-ignore.hbs`);

// Assets
mkdirSync(join(tmpProjPath(), 'apps', bundlerAppName, 'assets/a/b'), { recursive: true });
writeFileSync(join(tmpProjPath(), 'LICENSE'), 'license');
writeFileSync(join(tmpProjPath(), 'apps', bundlerAppName, 'README.md'), 'readme');
writeFileSync(join(tmpProjPath(), 'apps', bundlerAppName, 'assets/test1.hbs'), 'test');
writeFileSync(join(tmpProjPath(), 'apps', bundlerAppName, 'assets/test2.hbs'), 'test');
writeFileSync(join(tmpProjPath(), 'apps', bundlerAppName, 'assets/ignore.hbs'), 'IGNORE ME');
writeFileSync(join(tmpProjPath(), 'apps', bundlerAppName, 'assets/git-ignore.hbs'), 'IGNORE ME');
writeFileSync(join(tmpProjPath(), 'apps', bundlerAppName, 'assets/nx-ignore.hbs'), 'IGNORE ME');
writeFileSync(join(tmpProjPath(), 'apps', bundlerAppName, 'assets/a/b/nested-ignore.hbs'), 'IGNORE ME');

const project = readJson(`apps/${bundlerAppName}/project.json`);
project.targets.build.options.assets = [
`apps/${bundlerAppName}/*.md`,
{
input: `apps/${bundlerAppName}/assets`,
glob: '**/*.hbs',
output: 'assets',
ignore: ['ignore.hbs', '**/nested-ignore.hbs'],
},
'LICENSE',
];
updateFile(`apps/${bundlerAppName}/project.json`, JSON.stringify(project));

const result = await runNxCommandAsync(`build ${bundlerAppName}`);
expect(result.stdout).toContain(
`Successfully ran target build for project ${bundlerAppName}`
);
expect(() => checkFilesExist(
`dist/apps/${bundlerAppName}/main.js`,
`dist/apps/${bundlerAppName}/LICENSE`,
`dist/apps/${bundlerAppName}/README.md`,
`dist/apps/${bundlerAppName}/assets/test1.hbs`,
`dist/apps/${bundlerAppName}/assets/test2.hbs`
)).not.toThrow();
expect(workspaceFileExists(`dist/apps/${bundlerAppName}/assets/ignore.hbs`)).toBeFalsy();
expect(workspaceFileExists(`dist/apps/${bundlerAppName}/assets/git-ignore.hbs`)).toBeFalsy();
expect(workspaceFileExists(`dist/apps/${bundlerAppName}/assets/nx-ignore.hbs`)).toBeFalsy();
expect(workspaceFileExists(`dist/apps/${bundlerAppName}/assets/a/b/nested-ignore.hbs`)).toBeFalsy();
}, 120_000);

it('should create deno lib', async () => {
await runNxCommandAsync(`generate @nx/deno:lib ${bundlerLibName}`);
expect(readJson(`import_map.json`).imports).toEqual(
expect.objectContaining({
[`@proj/${bundlerLibName}`]: `./libs/${bundlerLibName}/mod.ts`,
})
);
expect(workspaceFileExists(`libs/${bundlerLibName}/mod.ts`)).toBeTruthy();
expect(
workspaceFileExists(`libs/${bundlerLibName}/src/${bundlerLibName}.test.ts`)
).toBeTruthy();
expect(
workspaceFileExists(`libs/${bundlerLibName}/src/${bundlerLibName}.ts`)
).toBeTruthy();
}, 120_000);

// Fixed by https://github.com/nrwl/nx-labs/pull/311
// it('should be able to use import alias of lib in app for build', async () => {
// const fnName = names(bundlerLibName).propertyName;
// updateFile(
// `apps/${bundlerAppName}/src/main.ts`,
// `import { ${fnName} } from '@proj/${bundlerLibName}'

// console.log(${fnName}())`
// );

// const result = await runNxCommandAsync(`build ${bundlerAppName}`);
// expect(result.stdout).toContain(
// `Successfully ran target build for project ${bundlerAppName}`
// );
// expect(workspaceFileExists(`dist/apps/${bundlerAppName}/main.js`)).toBeTruthy();
// }, 120_000);
charsleysa marked this conversation as resolved.
Show resolved Hide resolved
});

describe('--bundler esbuild', () => {
const bundlerAppName = uniq('deno-app-esbuild');
const bundlerLibName = uniq('deno-lib-esbuild');

it('should create deno app', async () => {
await runNxCommandAsync(`generate @nx/deno:app ${bundlerAppName} --bundler esbuild`);
expect(workspaceFileExists(`apps/${bundlerAppName}/src/main.ts`)).toBeTruthy();
}, 120_000);

it('should build deno app', async () => {
const result = await runNxCommandAsync(`build ${bundlerAppName}`);
expect(result.stdout).toContain(
`Successfully ran target build for project ${bundlerAppName}`
);
expect(workspaceFileExists(`dist/apps/${bundlerAppName}/main.js`)).toBeTruthy();
}, 120_000);

it('should build deno app w/assets', async () => {
// Workspace ignore files
writeFileSync(join(tmpProjPath(), '.gitignore'), `git-ignore.hbs`);
writeFileSync(join(tmpProjPath(), '.nxignore'), `nx-ignore.hbs`);

// Assets
mkdirSync(join(tmpProjPath(), 'apps', bundlerAppName, 'assets/a/b'), { recursive: true });
writeFileSync(join(tmpProjPath(), 'LICENSE'), 'license');
writeFileSync(join(tmpProjPath(), 'apps', bundlerAppName, 'README.md'), 'readme');
writeFileSync(join(tmpProjPath(), 'apps', bundlerAppName, 'assets/test1.hbs'), 'test');
writeFileSync(join(tmpProjPath(), 'apps', bundlerAppName, 'assets/test2.hbs'), 'test');
writeFileSync(join(tmpProjPath(), 'apps', bundlerAppName, 'assets/ignore.hbs'), 'IGNORE ME');
writeFileSync(join(tmpProjPath(), 'apps', bundlerAppName, 'assets/git-ignore.hbs'), 'IGNORE ME');
writeFileSync(join(tmpProjPath(), 'apps', bundlerAppName, 'assets/nx-ignore.hbs'), 'IGNORE ME');
writeFileSync(join(tmpProjPath(), 'apps', bundlerAppName, 'assets/a/b/nested-ignore.hbs'), 'IGNORE ME');

const project = readJson(`apps/${bundlerAppName}/project.json`);
project.targets.build.options.assets = [
`apps/${bundlerAppName}/*.md`,
{
input: `apps/${bundlerAppName}/assets`,
glob: '**/*.hbs',
output: 'assets',
ignore: ['ignore.hbs', '**/nested-ignore.hbs'],
},
'LICENSE',
];
updateFile(`apps/${bundlerAppName}/project.json`, JSON.stringify(project));

const result = await runNxCommandAsync(`build ${bundlerAppName}`);
expect(result.stdout).toContain(
`Successfully ran target build for project ${bundlerAppName}`
);
expect(() => checkFilesExist(
`dist/apps/${bundlerAppName}/main.js`,
`dist/apps/${bundlerAppName}/LICENSE`,
`dist/apps/${bundlerAppName}/README.md`,
`dist/apps/${bundlerAppName}/assets/test1.hbs`,
`dist/apps/${bundlerAppName}/assets/test2.hbs`
)).not.toThrow();
expect(workspaceFileExists(`dist/apps/${bundlerAppName}/assets/ignore.hbs`)).toBeFalsy();
expect(workspaceFileExists(`dist/apps/${bundlerAppName}/assets/git-ignore.hbs`)).toBeFalsy();
expect(workspaceFileExists(`dist/apps/${bundlerAppName}/assets/nx-ignore.hbs`)).toBeFalsy();
expect(workspaceFileExists(`dist/apps/${bundlerAppName}/assets/a/b/nested-ignore.hbs`)).toBeFalsy();
}, 120_000);

it('should create deno lib', async () => {
await runNxCommandAsync(`generate @nx/deno:lib ${bundlerLibName}`);
expect(readJson(`import_map.json`).imports).toEqual(
expect.objectContaining({
[`@proj/${bundlerLibName}`]: `./libs/${bundlerLibName}/mod.ts`,
})
);
expect(workspaceFileExists(`libs/${bundlerLibName}/mod.ts`)).toBeTruthy();
expect(
workspaceFileExists(`libs/${bundlerLibName}/src/${bundlerLibName}.test.ts`)
).toBeTruthy();
expect(
workspaceFileExists(`libs/${bundlerLibName}/src/${bundlerLibName}.ts`)
).toBeTruthy();
}, 120_000);

it('should be able to use import alias of lib in app for build', async () => {
const fnName = names(bundlerLibName).propertyName;
updateFile(
`apps/${bundlerAppName}/src/main.ts`,
`import { ${fnName} } from '@proj/${bundlerLibName}'

console.log(${fnName}())`
);

const result = await runNxCommandAsync(`build ${bundlerAppName}`);
expect(result.stdout).toContain(
`Successfully ran target build for project ${bundlerAppName}`
);
expect(workspaceFileExists(`dist/apps/${bundlerAppName}/main.js`)).toBeTruthy();
}, 120_000);
});
});
16 changes: 16 additions & 0 deletions e2e/deno-e2e/tests/deno-standalone.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,5 +386,21 @@ console.log(${fnName}())`
});
await promisifiedTreeKill(p.pid, 'SIGKILL');
}, 120_000);

it('should be able to use import alias of lib in app for build', async () => {
const fnName = names(libName).propertyName;
updateFile(
`src/main.ts`,
`import { ${fnName} } from '@proj/${libName}'

console.log(${fnName}())`
);

const result = await runNxCommandAsync(`build ${appName}`);
expect(result.stdout).toContain(
`Successfully ran target build for project ${appName}`
);
expect(workspaceFileExists(`dist/${appName}/main.js`)).toBeTruthy();
}, 120_000);
});
});
5 changes: 5 additions & 0 deletions packages/deno/executors.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
"schema": "./src/executors/emit/schema.json",
"description": "Bundle or transpile to a JavaScript file."
},
"esbuild": {
"implementation": "./src/executors/esbuild/esbuild.impl",
"schema": "./src/executors/esbuild/schema.json",
"description": "Bundle a package using EsBuild."
},
"run": {
"implementation": "./src/executors/run/run.impl",
"schema": "./src/executors/run/schema.json",
Expand Down
Loading
Loading