Skip to content

Commit

Permalink
* webpack - also bundle the plugin's module js file (if present).
Browse files Browse the repository at this point in the history
* webpack - ignore modules outside the plugin.

Part of #31
  • Loading branch information
bd82 committed Jun 13, 2018
1 parent fc12058 commit c4ecf1f
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 20 deletions.
26 changes: 16 additions & 10 deletions src/bundling.js
Original file line number Diff line number Diff line change
Expand Up @@ -894,22 +894,28 @@ const bundling = {
)}`
const pluginName = plugin.name

function addModuleAndPath(module) {
// avoids bundling modules defined outside the current plugin.
if (_.startsWith(module, pluginName)) {
const modulePath = `${relativePluginPath}${module.substr(
pluginName.length
)}.js`
amdModulesAndPaths.push({ module, modulePath })
}
}

if (plugin.module) {
addModuleAndPath(plugin.module)
}

_.forEach(plugin.provides.services, service => {
const module = service.module
const modulePath = `${relativePluginPath}${module.substr(
pluginName.length
)}.js`
amdModulesAndPaths.push({ module, modulePath })
addModuleAndPath(service.module)
})

_.forEach(
plugin.configures.services["command:commands"],
commandConfig => {
const module = commandConfig.service
const modulePath = `${relativePluginPath}${module.substr(
pluginName.length
)}.js`
amdModulesAndPaths.push({ module, modulePath })
addModuleAndPath(commandConfig.service)
}
)
})
Expand Down
76 changes: 76 additions & 0 deletions test/bundling_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,82 @@ describe("The, Exported bundling APIs", () => {
})
})

describe("webpack bundling plugin module", () => {
const pluginModuleBundle = path.resolve(
__dirname,
"resources/plugin_module_property/package.json"
)

it("Will add the plugin module to the bundle ", () => {
// the promise will be rejected if we could not resolve the
// ""sap/watt/something/somewhere/somehow.js" amd dependency in b2.js
return bundlingApi
.bundleFeature(pluginModuleBundle, {
bundler,
outDir: distFolder,
enableCaching: false
})
.then(result => {
const expectedOutputFile = `${distFolder}/config-preload.js`
const outputContents = fs.readFileSync(
expectedOutputFile,
"UTF-8"
)
expect(outputContents).to.include(
"from plugin.js yey"
)
})
})

afterEach(() => {
const jsOut = path.resolve(
`${path.dirname(
pluginModuleBundle
)}/config-preload.js`
)
fs.removeSync(jsOut)
fs.removeSync(`${jsOut}.map`)
})
})

describe("webpack ignoring modules from outside the plugin", () => {
const pluginModuleBundle = path.resolve(
__dirname,
"resources/module_outside_plugin/package.json"
)

it("Will add the plugin module to the bundle ", () => {
// the promise will be rejected if we could not resolve the
// ""sap/watt/something/somewhere/somehow.js" amd dependency in b2.js
return bundlingApi
.bundleFeature(pluginModuleBundle, {
bundler,
outDir: distFolder,
enableCaching: false
})
.then(result => {
const expectedOutputFile = `${distFolder}/config-preload.js`
const outputContents = fs.readFileSync(
expectedOutputFile,
"UTF-8"
)
expect(outputContents).to.not.include(
"from plugin.js yey"
)
})
})

afterEach(() => {
const jsOut = path.resolve(
`${path.dirname(
pluginModuleBundle
)}/config-preload.js`
)
fs.removeSync(jsOut)
fs.removeSync(`${jsOut}.map`)
})
})

describe("webpack error reporting", () => {
it("will fail & report an invalid webpack config", () => {
const myConfig = bundlingApi.getDefaultWebpackConfig(
Expand Down
4 changes: 2 additions & 2 deletions test/resources/common/rapidstart/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"services": {
"sample": {
"implements": "sap.webide.example.plugin.service.Sample",
"module": "sap.webide.example.plugin/service/b2"
"module": "sap.watt.bamba.rapidstart/service/b2"
}
}
},
Expand All @@ -18,7 +18,7 @@
"command:commands": [{
"id": "sap.webide.example.plugin.helloWorld",
"label": "{i18n>command_helloWorld}",
"service": "sap.webide.example.plugin/command/b1",
"service": "sap.watt.bamba.rapidstart/command/b1",
"available" : true,
"enabled" : true
}]
Expand Down
9 changes: 9 additions & 0 deletions test/resources/module_outside_plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "sample_bundled_feature",
"description": "used for tests",
"version": "1.0.0",
"enabledByDefault": true,
"bundledPlugins": {
"sap.watt.bamba.rapidstart": "file:rapidstart"
}
}
3 changes: 3 additions & 0 deletions test/resources/module_outside_plugin/rapidstart/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
define([], function() {
console.log("from plugin.js yey")
})
4 changes: 4 additions & 0 deletions test/resources/module_outside_plugin/rapidstart/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "sap.watt.bamba.rapidstart",
"module": "i.am.outside.plugin.and.shouldd.not.be.bundled/plugin"
}
9 changes: 9 additions & 0 deletions test/resources/plugin_module_property/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "sample_bundled_feature",
"description": "used for tests",
"version": "1.0.0",
"enabledByDefault": true,
"bundledPlugins": {
"sap.watt.bamba.rapidstart": "file:rapidstart"
}
}
3 changes: 3 additions & 0 deletions test/resources/plugin_module_property/rapidstart/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
define([], function() {
console.log("from plugin.js yey")
})
4 changes: 4 additions & 0 deletions test/resources/plugin_module_property/rapidstart/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "sap.watt.bamba.rapidstart",
"module": "sap.watt.bamba.rapidstart/plugin"
}
4 changes: 2 additions & 2 deletions test/resources/runtime_dep/rapidstart/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"services": {
"sample": {
"implements": "sap.webide.example.plugin.service.Sample",
"module": "sap.webide.example.plugin/service/b2"
"module": "sap.watt.bamba.rapidstart/service/b2"
}
}
},
Expand All @@ -18,7 +18,7 @@
"command:commands": [{
"id": "sap.webide.example.plugin.helloWorld",
"label": "{i18n>command_helloWorld}",
"service": "sap.webide.example.plugin/command/b1",
"service": "sap.watt.bamba.rapidstart/command/b1",
"available" : true,
"enabled" : true
}]
Expand Down
4 changes: 2 additions & 2 deletions test/resources/webpack_error/rapidstart/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"services": {
"sample": {
"implements": "sap.webide.example.plugin.service.Sample",
"module": "sap.webide.example.plugin/service/b2"
"module": "sap.watt.bamba.rapidstart/service/b2"
}
}
},
Expand All @@ -18,7 +18,7 @@
"command:commands": [{
"id": "sap.webide.example.plugin.helloWorld",
"label": "{i18n>command_helloWorld}",
"service": "sap.webide.example.plugin/command/b1",
"service": "sap.watt.bamba.rapidstart/command/b1",
"available" : true,
"enabled" : true
}]
Expand Down
4 changes: 2 additions & 2 deletions test/resources/webpack_warning/rapidstart/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"services": {
"sample": {
"implements": "sap.webide.example.plugin.service.Sample",
"module": "sap.webide.example.plugin/service/b2"
"module": "sap.watt.bamba.rapidstart/service/b2"
}
}
},
Expand All @@ -18,7 +18,7 @@
"command:commands": [{
"id": "sap.webide.example.plugin.helloWorld",
"label": "{i18n>command_helloWorld}",
"service": "sap.webide.example.plugin/command/b1",
"service": "sap.watt.bamba.rapidstart/command/b1",
"available" : true,
"enabled" : true
}]
Expand Down
4 changes: 2 additions & 2 deletions test/resources2/quickstart/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
},"services": {
"sample": {
"implements": "sap.webide.example.plugin.service.Sample",
"module": "sap.webide.example.plugin/service/2"
"module": "sap.watt.bamba.quickstart/service/2"
},
"sample2": {
"implements": "sap.webide.example.plugin.service.Sample",
"module": "sap.webide.example.plugin/service/3"
"module": "sap.watt.bamba.quickstart/service/3"
}
}
},
Expand Down

0 comments on commit c4ecf1f

Please sign in to comment.