Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2226 from cgewecke/truffle-library
Browse files Browse the repository at this point in the history
Generate truffle library webpack bundle for package main
  • Loading branch information
gnidan authored Jul 28, 2019
2 parents 8f79054 + ccdf497 commit 86e39f8
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/truffle-core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ module.exports = {
contracts: require("truffle-workflow-compile"),
package: require("./lib/package"),
test: require("./lib/test"),
version: pkg.version
version: pkg.version,
ganache: require("ganache-core")
};
14 changes: 12 additions & 2 deletions packages/truffle/cli.webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ module.exports = {
"services",
"analytics",
"main.js"
),
library: path.join(
__dirname,
"../..",
"node_modules",
"truffle-core",
"index.js"
)
},
target: "node",
Expand All @@ -42,7 +49,9 @@ module.exports = {
context: rootDir,
output: {
path: outputDir,
filename: "[name].bundled.js"
filename: "[name].bundled.js",
library: "",
libraryTarget: "commonjs"
},
devtool: "source-map",
module: {
Expand Down Expand Up @@ -75,7 +84,8 @@ module.exports = {
new webpack.DefinePlugin({
BUNDLE_VERSION: JSON.stringify(pkg.version),
BUNDLE_CHAIN_FILENAME: JSON.stringify("chain.bundled.js"),
BUNDLE_ANALYTICS_FILENAME: JSON.stringify("analytics.bundled.js")
BUNDLE_ANALYTICS_FILENAME: JSON.stringify("analytics.bundled.js"),
BUNDLE_LIBRARY_FILENAME: JSON.stringify("library.bundled.js")
}),

// Put the shebang back on.
Expand Down
1 change: 1 addition & 0 deletions packages/truffle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"url": "https://github.com/trufflesuite/truffle/issues"
},
"version": "5.0.29",
"main": "./build/library.bundled.js",
"bin": {
"truffle": "./build/cli.bundled.js"
},
Expand Down
97 changes: 97 additions & 0 deletions packages/truffle/test/scenarios/library/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
const assert = require("assert");

describe("Truffle Library APIs", () => {
// Avoid `npm test:raw`
if (process.env.NO_BUILD) return;

let truffle;
before(function() {
this.timeout(5000);
truffle = require("../../../build/library.bundled.js");
});

it("truffle.build API definition", () => {
assert(truffle.build, "build undefined");
assert(truffle.build.clean, "build.clean undefined");
assert(truffle.build.build, "build.build undefined");
});

it("truffle.create API definition", () => {
assert(truffle.create, "create undefined");
assert(truffle.create.contract, "create.contract undefined");
assert(truffle.create.test, "create.test undefined");
assert(truffle.create.migration, "create.migration undefined");
});

it("truffle.console API definition", () => {
// This one returns a constructor.
assert(truffle.console, "console undefined");
});

it("truffle.contracts API definition", () => {
assert(truffle.contracts.compile, "contracts.compile undefined");
assert(
truffle.contracts.collectCompilations,
"contracts.collectCompilations undefined"
);
assert(
truffle.contracts.compileSources,
"contracts.compileSources undefined"
);
assert(
truffle.contracts.reportCompilationStarted,
"contracts.reportCompilationStarted undefined"
);
assert(
truffle.contracts.reportCompilationFinished,
"contracts.reportCompilationFinished undefined"
);
assert(
truffle.contracts.reportNothingToCompile,
"contracts.reportNothingToCompile undefined"
);
assert(
truffle.contracts.writeContracts,
"contracts.writeContracts undefined"
);
});

it("truffle.package API definition", () => {
assert(truffle.package.publish, "package.publish undefined");
assert(truffle.package.install, "package.install undefined");
assert(truffle.package.digest, "package.digest undefined");
assert(
truffle.package.publishable_artifacts,
"package.publishable_artifacts undefined"
);
});

it("truffle.test API", () => {
assert(truffle.test.run, "test.run undefined");
assert(truffle.test.createMocha, "test.createMocha undefined");
assert(truffle.test.getAccounts, "test.getAccounts undefined");
assert(
truffle.test.compileContractsWithTestFilesIfNeeded,
"test.withTestFiles undefined"
);
assert(
truffle.test.performInitialDeploy,
"test.performInitialDeploy undefined"
);
assert(
truffle.test.defineSolidityTests,
"test.defineSolidityTests undefined"
);
assert(truffle.test.setJSTestGlobals, "test.setJSTestGlobals undefined");
});

it("truffle.version API", () => {
assert(truffle.version, "truffle.version undefined");
});

it("truffle.ganache", () => {
assert(truffle.ganache, "ganache undefined");
assert(truffle.ganache.provider, "ganache.provider undefined");
assert(truffle.ganache.server, "ganache.server undefined");
});
});

0 comments on commit 86e39f8

Please sign in to comment.