Skip to content

Commit

Permalink
fs-extra
Browse files Browse the repository at this point in the history
  • Loading branch information
jogold committed Jun 18, 2020
1 parent 1a3187c commit 05025bc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
"@aws-cdk/cloud-assembly-schema/semver/**",
"@aws-cdk/cloudformation-include/yaml",
"@aws-cdk/cloudformation-include/yaml/**",
"@aws-cdk/core/fs-extra",
"@aws-cdk/core/fs-extra/**",
"@aws-cdk/core/minimatch",
"@aws-cdk/core/minimatch/**",
"@aws-cdk/cx-api/semver",
Expand Down
8 changes: 3 additions & 5 deletions packages/@aws-cdk/core/lib/asset-staging.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as cxapi from '@aws-cdk/cx-api';
import * as crypto from 'crypto';
import * as fs from 'fs';
import * as fs from 'fs-extra';
import * as os from 'os';
import * as path from 'path';
import { AssetHashType, AssetOptions } from './assets';
Expand Down Expand Up @@ -121,7 +121,7 @@ export class AssetStaging extends Construct {
// Asset has been bundled
if (this.bundleDir) {
// Rename bundling directory to staging directory
fs.renameSync(this.bundleDir, targetPath);
fs.moveSync(this.bundleDir, targetPath);
return;
}

Expand All @@ -140,9 +140,7 @@ export class AssetStaging extends Construct {
private bundle(options: BundlingOptions): string {
// Temp staging directory in the working directory
const stagingTmp = path.join('.', STAGING_TMP);
if (!fs.existsSync(stagingTmp)) {
fs.mkdirSync(stagingTmp);
}
fs.ensureDirSync(stagingTmp);

// Create temp directory for bundling inside the temp staging directory
const bundleDir = fs.mkdtempSync(path.join(stagingTmp, 'asset-bundle-'));
Expand Down
2 changes: 2 additions & 0 deletions packages/@aws-cdk/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,15 @@
"ts-mock-imports": "^1.3.0"
},
"dependencies": {
"fs-extra": "^9.0.1",
"minimatch": "^3.0.4",
"@aws-cdk/cx-api": "0.0.0",
"@aws-cdk/cdk-assets-schema": "0.0.0",
"@aws-cdk/cloud-assembly-schema": "0.0.0",
"constructs": "^3.0.2"
},
"bundledDependencies": [
"fs-extra",
"minimatch"
],
"homepage": "https://github.com/aws/aws-cdk",
Expand Down
11 changes: 10 additions & 1 deletion packages/@aws-cdk/core/test/test.staging.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as cxapi from '@aws-cdk/cx-api';
import * as fs from 'fs';
import * as fs from 'fs-extra';
import { Test } from 'nodeunit';
import * as os from 'os';
import * as path from 'path';
import * as sinon from 'sinon';
import { App, AssetHashType, AssetStaging, BundlingDockerImage, Stack } from '../lib';

const STUB_INPUT_FILE = '/tmp/docker-stub.input';
Expand All @@ -26,6 +27,7 @@ export = {
fs.unlinkSync(STUB_INPUT_FILE);
}
cb();
sinon.restore();
},

'base case'(test: Test) {
Expand Down Expand Up @@ -103,6 +105,8 @@ export = {
const app = new App();
const stack = new Stack(app, 'stack');
const directory = path.join(__dirname, 'fs', 'fixtures', 'test1');
const ensureDirSyncSpy = sinon.spy(fs, 'ensureDirSync');
const mkdtempSyncSpy = sinon.spy(fs, 'mkdtempSync');

// WHEN
new AssetStaging(stack, 'Asset', {
Expand All @@ -127,6 +131,11 @@ export = {
'tree.json',
]);

// asset is bundled in a directory inside .cdk.staging
const stagingTmp = path.join('.', '.cdk.staging');
test.ok(ensureDirSyncSpy.calledWith(stagingTmp));
test.ok(mkdtempSyncSpy.calledWith(sinon.match(path.join(stagingTmp, 'asset-bundle-'))));

test.done();
},

Expand Down

0 comments on commit 05025bc

Please sign in to comment.