Skip to content

Commit

Permalink
Support .cjs extension for webpack (#204)
Browse files Browse the repository at this point in the history
Co-authored-by: Jesse MacFadyen <[email protected]>
  • Loading branch information
ahmed-musallam and purplecabbage authored Feb 8, 2025
1 parent 637a18e commit 1e03006
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/build-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const getWebpackConfigPath = async (actionPath, root) => {
let configPath = null

do {
const paths = await globby([path.join(parentDir, '*webpack-config.js')])
const paths = await globby([path.join(parentDir, '*webpack-config.{js,cjs}')])
if (paths && paths.length > 0) {
configPath = paths[0]
}
Expand Down
50 changes: 49 additions & 1 deletion test/build.actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,55 @@ describe('build by bundling js action file with webpack', () => {
},
target: 'node'
}])
expect(globby).toHaveBeenCalledWith(expect.arrayContaining([path.resolve('/actions/*webpack-config.js')]))
expect(globby).toHaveBeenCalledWith(expect.arrayContaining([path.resolve('/actions/*webpack-config.{js,cjs}')]))
expect(utils.zip).toHaveBeenCalledWith(path.normalize('/dist/actions/sample-app-include-1.0.0/action-temp'),
path.normalize('/dist/actions/sample-app-include-1.0.0/action.zip'))
expect(Object.keys(global.fakeFileSystem.files())).toEqual(expect.arrayContaining(['/includeme.txt']))
})

test('should bundle a single action file using webpack and zip it with includes using webpack-config.cjs in actions root', async () => {
global.fakeFileSystem.reset()
global.fakeFileSystem.addJson({
'actions/action.js': global.fixtureFile('/sample-app-includes/actions/action.js'),
'includeme.txt': global.fixtureFile('/sample-app-includes/includeme.txt'),
'manifest.yml': global.fixtureFile('/sample-app-includes/manifest.yml'),
'package.json': global.fixtureFile('/sample-app-includes/package.json')
})
globby.mockReturnValueOnce(['/includeme.txt'])
globby.mockReturnValueOnce(['actions/mock.webpack-config.cjs'])

jest.mock('actions/mock.webpack-config.cjs', () => {
return [{
mode: 'none',
optimization: { somefakefield: true },
output: { fake: false },
entry: ['file.js'],
resolve: {
extensions: ['html', 'json', 'css'],
mainFields: ['another'],
anotherFake: ['yo']
},
plugins: ['hello'],
target: 'cannotovewrite'
}]
}, { virtual: true })

await buildActions(global.sampleAppIncludesConfig)
expect(webpackMock.run).toHaveBeenCalledTimes(1)
expect(webpack).toHaveBeenCalledWith([{
entry: [path.resolve('actions/file.js'), path.resolve('/actions/action.js')],
mode: 'none',
optimization: { minimize: false, somefakefield: true },
output: { fake: false, filename: 'index.js', libraryTarget: 'commonjs2', path: path.normalize('/dist/actions/sample-app-include-1.0.0/action-temp') },
plugins: ['hello', {}],
resolve: {
anotherFake: ['yo'],
extensions: ['html', 'json', 'css', '.js', '.json'],
mainFields: ['another', 'main']
},
target: 'node'
}])
expect(globby).toHaveBeenCalledWith(expect.arrayContaining([path.resolve('/actions/*webpack-config.{js,cjs}')]))
expect(utils.zip).toHaveBeenCalledWith(path.normalize('/dist/actions/sample-app-include-1.0.0/action-temp'),
path.normalize('/dist/actions/sample-app-include-1.0.0/action.zip'))
expect(Object.keys(global.fakeFileSystem.files())).toEqual(expect.arrayContaining(['/includeme.txt']))
Expand Down

0 comments on commit 1e03006

Please sign in to comment.